0

This is my first foray into creating a daemon so bear with me if I say some noob stuff.

I wrote a test script using AppleScript. Eventually, this will be more robust and be a meeting announcer and some other notifications to start my day. Here's the script for now:

say "Hello Steve, the job has launched!"

Here's the plist:

enter image description here

I saved this in /Library/LaunchDaemons as local.jeeves.plist. I confirmed it is there by visually finding it and running:

launchctl list

enter image description here

Running

 launchctl list | grep local.Jeeves

also confirmed it was there.

I confirmed the script referenced by the Program key is in that directory. It also functions as I can run it from AppleScript

enter image description here

Back to the plist. I loaded it by running:

launchctl load /Library/LaunchDaemons/local.jeeves.plist

Terminal did not produce any errors.

If I run:

launchctl start local.jeeves

or

launchctl start local.Jeeves

no results. No errors but the script does not run.

So I did some digging into my system.log and found these errors:

Aug 28 15:26:17 Steves-MBP com.apple.xpc.launchd[1] (com.apple.xpc.launchd.user.domain.501.100009.Aqua): Could not read path: path = /Users/xxxxxxx/Library/LaunchDaemons/local.jeeves.plist, error = 2: No such file or directory
Aug 28 15:27:33 Steves-MBP com.apple.xpc.launchd[1] (com.apple.xpc.launchd.user.domain.501.100009.Aqua): Could not read path: path = /Users/xxxxxxxx/Library/LaunchDaemons/local.jeeves.plist, error = 2: No such file or directory
Aug 28 15:28:05 Steves-MBP com.apple.xpc.launchd[1] (local.Jeeves[14803]): Could not find and/or execute program specified by service: 13: Permission denied: /Users/xxxxxxx/Scripts/AppleScripts/testScript.scpt
Aug 28 15:28:05 Steves-MBP com.apple.xpc.launchd[1] (local.Jeeves[14803]): Service setup event to handle failure and will not launch until it fires.
Aug 28 15:28:05 Steves-MBP com.apple.xpc.launchd[1] (local.Jeeves[14803]): Service exited with abnormal code: 78

So now I know the issue, or kind of. Is this a permission to the directory issue or can't find the directory at all issue?

PruitIgoe
  • 6,166
  • 16
  • 70
  • 137

1 Answers1

-1

A couple of points... First, if you want to load a job from /Library/LaunchDaemons, you'll need administrator privileges, meaning you'll likely have to use sudo launchctl to get it going. That's part of the problem you're seeing (and likely why the logs are complaining about '/Users/xxxxxxx/Library/LaunchDaemons': a location which you didn't specify and which doesn't exist...).

Second, LaunchDaemons are meant to be completely faceless: they are background tasks that often run outside of a user's login session, and so aren't expected to have access to interface elements like the speech synthesizer or the window server. If you mean this to be an announcement service, you should run it as a LaunchAgent, not a LaunchDaemon. If you move the plist file to '/Users/xxxxxxx/Library/LaunchAgents' and try to load it again, everything should work perfectly.

Ted Wrigley
  • 2,921
  • 2
  • 7
  • 17