Archive

Archive for March, 2016

El Capitan open and quit an app every 6 hours

March 18th, 2016 No comments

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

<?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>com.exit.evocam.1</string>
    <key>Program</key>
    <string>/usr/bin/osascript</string>
    <key>ProgramArguments</key>
    <array>
        <string>osascript</string>
        <string>-e</string>
        <string>tell application "Evocam" to quit</string>
    </array>
    <key>StartCalendarInterval</key>
    <dict>
        <key>Hour</key>
        <integer>12</integer>
        <key>Minute</key>
        <integer>00</integer>
    </dict>
</dict>
</plist>

To Launch EvoCam:

Saved this to :
~/Library/LaunchAgents/com.launch.evocam.1.plist

<?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>com.launch.evocam.1</string>
    <key>Program</key>
    <string>/usr/bin/osascript</string>
    <key>ProgramArguments</key>
    <array>
        <string>osascript</string>
        <string>-e</string>
        <string>tell application "Evocam" to open</string>
    </array>
    <key>StartCalendarInterval</key>
    <dict>
        <key>Hour</key>
        <integer>12</integer>
        <key>Minute</key>
        <integer>01</integer>
    </dict>
</dict>
</plist>

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.

Categories: Latest, Mac and OSX Tags: