The way I would do it is to use an application called launchd
to open the automator script how ever often you need (e.g. every few seconds). This website describes how to set it up. Basically you have to first save your automator script as an application into a certain folder (e.g. Documents), then write a short xml script which tells launchd
which file to open and how often to do it.
Below is a sample script:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>com.NAME.test</string>
<key>Program</key>
<string>/Users/USERNAME/Documents/test.app/Contents/MacOS/Application Stub</string>
<key>StartInterval</key>
<integer>5</integer>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
Open a new "Plain text" TextEdit document and paste in the above. Replace the Label (com.NAME.test
) with whatever you want; I usually just put my name in there, followed by the name of the script. Next change the line under Program
to the location of your ".app" file you saved earlier, remembering to change USERNAME
to your username. Keep in mind that the /Contents/MacOS/Application Stub
needs to be right after the ".app" part so that the script will start your application. Then change the line under StartInterval
to the number of seconds you want the script to wait before it runs again.
After you're done editing the script, save it to "/Users/USERNAME/Library/LaunchAgents/com.NAME.test.plist," of course changing USERNAME
to your username and com.NAME.test
to the Label used in the xml script. If it asks if you want to save it with the ".plist" extension, choose yes. Once the file's saved, open up Terminal (/Applications/Utilities/Terminal.app) and type in the command launchctl load /Users/USERNAME/Library/LaunchAgents/com.NAME.test.plist
, changing the file name to the filepath of your ".plist" file. Use unload
instead of load
to stop the script from running.
For me a gear icon kept appearing in the menu bar every time the script ran, so I found on this and this website that you can stop it by adding "Run Shell Script" to the very top of your Automator script, then typing in the box killall ScriptMonitor || true
.