I wrote a very simple launch agent. In the first version, I compiled AppleScript file (.scpt), set it to be executable, and put inside the agent’s Program property. I made sure the file runs as expected both from within ScriptEditor and Terminal via osascript. As for the launch agent itself, my look-up showed its absence in the override database (which means success). However launchctl list | grep -i my_job revealed it being loaded but exiting with error 1 which usually points to impermissible errors. I looked closer at my agent’s “Program” property and re-wrote it so that it would rely on “ProgramArguments” instead and included this script file as an argument to the command line utility osascript which, in turn, had to be given to the shell command itself (/bin/sh -c osascript my_script.scpt).
Only then it was complete success. Which begs the question: are launch agents unable to run AppleScript compiled code files as the arguments to their “Program” property without shell?
The usual way is to specify /usr/bin/osascript as the value for Program and repeat osascript in the first item of the ProgramArguments array
<key>Program</key>
<string>/usr/bin/osascript</string>
<key>ProgramArguments</key>
<array>
<string>osascript</string>
<string>/Users/myself/path/to/script.scpt</string>
</array>
Thank you. But my question was why it’s not possible to specify the path to the AppleScript script file as a value of “Program”?
Because a compiled AppleScript is not a program!
It’s a script which needs to executed by an AppleScript program, i.e. osascript
or you can save the script as an AppleScript application
Here is a plist file I am currently using to run a script at login on my Mac
its path is ~/Library/LaunchAgents/com.rmf.startup.plist
As you can see it does have the path to script
Yes. But it’s not in the form of
Program
/Users/robert/Scripts/StartupScript.scpt
which is what my question was about.