El Capitan open and quit an app every 6 hours

after opening “Automator” and spending 2 minutes dragging and dropping actions I though no this need to be done with AppleScript !

Then looking at the fact the AppleScript would need to run constantly I thought this is best for a Cron job!

Looking at apples tech docs Cron is being depricated!

Right so the replacement is to use Launch Daemons and Agents !

See:
https://developer.apple.com/library/mac/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/CreatingLaunchdJobs.html

 

So I want to exit and re launch an app called EvoCam every 6 hours, my solution is to create 8 plist files the logic is:

24 / 6 = 4

and I want it to Exit EvoCam on the hour and re open it every 1 minute passed the hour.

so 2 * 4 = 8

To exit EvoCam:

I saved this file to (where ~ is your user directory):

~/Library/LaunchAgents/com.exit.evocam.1.plist
[cc lang=”xml” tab_size=”2″ lines=”40″]


Label
com.exit.evocam.1
Program
/usr/bin/osascript
ProgramArguments

osascript
-e
tell application “Evocam” to quit

StartCalendarInterval

Hour
12
Minute
00

[/cc]

To Launch EvoCam:

Saved this to :
~/Library/LaunchAgents/com.launch.evocam.1.plist
[cc lang=”xml” tab_size=”2″ lines=”40″]


Label
com.launch.evocam.1
Program
/usr/bin/osascript
ProgramArguments

osascript
-e
tell application “Evocam” to open

StartCalendarInterval

Hour
12
Minute
01

[/cc]

Then duplicate each file 4 times advancing the Hour by 6 , so it quits the app every 6 hours and opens it at every one minute past.

Maybe someone can explain hot to get the .plist file to Loop every 6 hours?
For now this will do!

Obviously you change “EvoCam to the name of the app or program you want to launch.

Leave a Reply

Your email address will not be published. Required fields are marked *