Bring Application to Front – How to Bring Application to Front Every 15 Minutes on macOS Lion

applescriptautomationlaunchdmacos

I have a free or cheap little app called Desktop Task Timer LE that I've been using to track my time as I work on various projects. I'd like to have it pop up as the foreground app every 15 minutes to prevent me from forgetting to stop/change the timer after I've moved on to a different task. I know I can have the app launch using a script in Automator or AppleScript, but I don't know how to have that script fire off every 15 minutes. I've read about using Launchd and iCal, but I'm still not sure how to do it. (Actually, iCal is probably simple, but I'd like to avoid using it for this.) Any ideas?

Also, a further feature would be to have it pop up after 5 (or x) minutes of inactivity on the computer. Not sure if this would work for my needs, but I'd like to test it if possible.

Best Answer

~/Library/LaunchAgents/com.stackoverflow.open.desktop.task.timer.plist

<?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.stackoverflow.open.desktop.task.timer</string>
    <key>ProgramArguments</key>
    <array>
        <string>open</string>
        <string>-a</string>
        <string>Desktop Task Timer LE</string>
    </array>
    <key>StartInterval</key>
    <integer>900</integer> <!-- every 900 seconds -->
    <key>RunAtLoad</key> <!--run on the 0th second-->
    <true/>
</dict>
</plist>

launchctl load ~/Library/LaunchAgents/com.stackoverflow.open.desktop.task.timer.plist or log out and back in.

crontab -e

*/15 * * * * open -a "Desktop Task Timer LE"
  • You can use a different editor like EDITOR=nano crontab -e
  • crontab -l lists currently scheduled tasks
  • crontab /path/to/file updates the table from an external file
Related Question