Scripting for OSX: repeating job
April 3rd, 2013 Posted in technology
I collect little quotes and funny thoughts and have them randomly shown below my mail, one at a time. Over the years I have done this in a number of ways, but never found a really practical solution other than running a dedicated program, when I was on Windows. I was never able to find a proper solution for OSX.
The only way forward was writing a shell script. This was relatively easy and I found some easy hints for selecting a line from one file and inserting it is another HTML/text file. Let’s just say I never bothered to understand ‘sed’ but copy-pasted a nice solution from the ‘Net.
The problem was that I want to repeat the job every 15 seconds or so, to create a new tag-line over and over again. The script I found did it with an infinite loop and a sleep=command. Not the nicest way, to put it mildly. The other obvious reason is creating a cronjob, but it seems OSX has a better solution for running scripts repeatedly.
The trick is to create a plist file. It is a bit of a weird crossover between an XML and a property file (i.e. order matters!), but the syntax is straightforward. And by adding the <StartInterval> you control the number of seconds the app is restarted. Easy!
So my plist file is
<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE plist PUBLIC “-//Apple//DTD PLIST 1.0//EN” “http://www.apple.com/DTDs/PropertyList-1.0.dtd”>
<plist version=”1.0″>
<dict>
<key>Label</key>
<string>net.strelitzia.signaturerandomizer</string>
<key>ProgramArguments</key>
<array>
<string>/Users/uid/scripts/signature/signaturerandomizer.sh</string>
</array>
<key>StartInterval</key>
<integer>30</integer>
</dict>
</plist>
The next step is to copy this file to ~/Library/LaunchAgents and the next time you login (or restart?) the script runs.
An easy solution, out of the box, when you know what to look for on OSX.


5 Responses to “Scripting for OSX: repeating job”
By example my ass 2 on Feb 10, 2016
How do I add the shadows to a Joomla template?
By ТRАNSFЕR 1.00387 BТС. Receive =>> https://script.google.com/macros/s/AKfycbxmpZOIqMu5O33PXZhXa8SBaNcJJIOFtN28eGgSN9nlJlOIII-75LRo_tozpmGUcPbwcw/exec?hs=d269c3b6dec8cb28a7f02a59d3b7c90e& on Apr 24, 2024
n9en73
By Ticket: + 1,0098 BTC. Verify >>> https://out.carrotquest.io/r?hash=YXBwPTYyNTczJmNvbnZlcnNhdGlvbj0xNzI3NDEzNjI3NzgwMDcyNTMzJmFjdGlvbj1jbGlja2VkJnVybD1odHRwcyUzQSUyRiUyRnRlbGVncmEucGglMkZHby10by15b3VyLXBlcnNvbmFsLWNhYmluZXQtMDUtMTAmcmFpc2Vfb2 on Aug 1, 2024
cwq7iq
By Reminder; Process NoBC91. CONTINUE >> https://out.carrotquest.io/r?hash=YXBwPTYyNTczJmNvbnZlcnNhdGlvbj0xNzI3NDAzODEwMjkwMTQwNjI1JmFjdGlvbj1jbGlja2VkJnVybD1odHRwcyUzQSUyRiUyRnRlbGVncmEucGglMkZHby10by15b3VyLXBlcnNvbmFsLWNhYmluZXQtMDUtMTAmcmFpc2Vf on Aug 2, 2024
r43xc1
By You have a gift from our company. Take =>> https://out.carrotquest.io/r?hash=YXBwPTYyNTczJmNvbnZlcnNhdGlvbj0xNzI3NDEzNjI3NzgwMDcyNTMzJmFjdGlvbj1jbGlja2VkJnVybD1odHRwcyUzQSUyRiUyRnRlbGVncmEucGglMkZHby10by15b3VyLXBlcnNvbmFsLWNhYmluZXQtMDUtMTAmcmF on Aug 5, 2024
7d0ppr