Ultimately, I would like to use launchd to call AppleScripts, but it appears that although osascript works famously from the Terminal, when saved as a shell script, it fails. For example, I am using a short test AppleScript, saved as 2.scpt on the Desktop:
on run
tell application "Finder"
display dialog "Here is the second script"
end tell
end run
I used a Finder tell for the display dialog, otherwise osascript could not call it at all, even from Terminal. I used the run handler in the hopes that osascript could call it from this shell script:
[code]#!/bin/sh
this should run the Second Script on the desktop
osascript ‘~/Desktop/2.scpt’[/code]
So, anyway, this command from Terminal works fine:
osascript '~/Desktop/2.scpt'
However, when I try to run it from the shell script, still using the command line in Terminal:
secondscript.sh
I get this error:
osascript: ~/Desktop/2.scpt: No such file or directory
When I incorporate the shell script into a launchd plist, this is what happens when called:
launchd[701]: RunSecondScript: execve(): No such file or directory
I am not a trained UNIX programmer, but I can fashion basic shell scripts. All I want to do is to use launchd to automate the execution of a few scripts on my machine, but all the scripts I want to launch are AS, and launchd does not seem to run those in its native form. I also tried saving my test script as an application, and launchd still did not recognize it.
Any advice or instruction is welcome and appreciated.