I have an AppleScript applet comprising only one little handler that needs to run as root because it’s the only way I can think of to make my other, main AppleScript applet—which will call that handler—work, for a friend who (foolishly) insists on having his Mac admin account with a blank password. sudo doesn’t work with a blank password, and if I store his blank password in his Keychain, then AppleScript ultimately will:
do shell script "[command]" password "" with administrator privileges
…which still puts up the system password entry dialog, which I’m trying to avoid after it gets stored in the Keychain.
I can get this in AppleScript to launch the little companion AppleScript applet:
do shell script "bin/sh -c \"" & quoted form of "/Users/schmye/Desktop/Companion Applet.app/Contents/MacOS/applet" & "\" &> /dev/null &" with administrator privileges
…which nicely “detaches” from Script Editor or from another AppleScript applet that invokes it. And the launched applet will successfully execute its handler’s root-required command when my other, main AppleScript applet calls it:
tell application "Companion Applet" to theHandler()
I need the little companion applet to be running as root at all times, but I can’t seem to get it to work when launched from a launchd job. I’m using Launch Control to help write my launchd job as a root Global Daemon. A launchd job is not itself a shell, so that’s why for comparison & proof-of-concept purposes, I (unnecessarily) wrote the above do shell script with a sub-shell, but which indeed is necessary in my launchd command:
That launchd job does launch my little companion applet, but calling its handler from my other, main applet this time only returns an Apple Events timeout error after the usual delay. Appending the “run-in-background” ampersand command:
…doesn’t cause it to “detach” like it did when I ran it above in the do shell script, the absence of which I thought at first was causing the Apple Events timeout error because possibly launchd was hanging-on to it and not sharing it with my other applet calling the handler — but in fact, the companion applet wouldn’t even launch at all with the addition of the backgrounder ampersand suffix.
This is my plist that got created in /Library/LaunchDaemons. Any launchd jockeys in the house who can tell me what I’m getting wrong?
AppleScript: 2.1.2
Operating System: Mac OS X (10.6.8)