Reputation: 23
im very new to OSX shell programming (so be gentle) however i am a computer science uni graduate (albeit 15 years ago!) so programming around unix systems is nothing new to me.
I have been stuck on why my plist in /Library/LaunchDaemons/ is not running. I have spent half the day chasing down loose ends that have not gone anywhere hence me posting here to you fine folk.
My very simple plist is below. Please note that "MyApp" is just an apple script that (at the moment) just terminates and reloads a specific application via the shell command "killall". This part works just fine (ie when i double click it in finder, the desired app does indeed terminate and reload, and also from within the applescript editor when i click "compile" and "run"). FYI i have also set this applescript to now write a time/datestamp to a log file every time it is called, to make it clear to me when it is invoked....
.... and it never is automatically!
the only time i can get it to run is when i:
a) double click on MyApp in finder.
b) "run" it from within the applescript editor
c) command prompt: 'launchctl start MyApp'
I confirm that the script does run by any of the above by 'tail -f' on my log file, and a close eye on console output.....
HOWEVER, what i really want is:
d) for it to run automatically at boot time, and then invoked once every subsequent hour.
heres my plist code:
<?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>MyApp</string>
<key>ProgramArguments</key>
<array>
<string>/Applications/MyApp.app/Contents/MacOS/applet</string>
</array>
<key>StartInterval</key>
<integer>3600</integer>
<key>WorkingDirectory</key>
<string>/Applications/MyApp.app/Contents/MacOS/</string>
</dict>
</plist>
and heres the directory permissions
iMac:LaunchDaemons keiran_harris$ ls -las
total 24
0 drwxr-xr-x 5 root wheel 170 25 Jan 19:38 .
0 drwxr-xr-x+ 64 root wheel 2176 24 Jan 12:19 ..
16 -r--r--r--@ 1 root wheel 732 26 Jan 13:32 MyApp.plist
has anybody got any ideas on what the heck i am doing wrong?
i would be oh so grateful.
thanks in advance gurus!
Keiran.
PS> have scrutinised other similar problems in this forum, to no avail:
VERY simple Launchd plist not running my script
launchd file runs manually but not automatically
My mac osx launched plist won't run
Upvotes: 2
Views: 1262
Reputation: 125788
AppleScripts can only run as part of an Aqua (GUI) session, while LaunchDaemons run in system context, independently of GUI sessions. You'll either need to rewrite the script using some other (non-GUI-dependent) scripting technology (shell scripting would work), or use a LaunchAgent (which normally run inside user GUI sessions) instead of a Daemon. See the Execution Context Summary section of Technical Note TN2083: Daemons and Agents -- Bootstrap Namespace is the relevant column.
Upvotes: 1