I need to be able to run AppleScript in a shell script. I am using "AppleScript Runner" in order to be in interactive mode, so that dialogs etc. are supported. I've got it working, but I need to get the exit status of the AppleScript Runner app back to the shell, so I can see if there were any errors in the script.
Here is my shell script:
output=$(/usr/bin/osascript << EOT
tell application "AppleScript Runner"
do script "somescript.scpt"
end
EOT)
status=$?
Here my variable $status only ends up with the exit status of the osascript command (which will be 0 whether or not somescript.scpt actually ran successfully), and not the exit status of the app AppleScript Runner.
Does any one know how I might accomplish this?
Thanks!
The -e flag prints errors to stderr and is the default. So you just need to read stderr.
This answer might help you if you aren't familiar with that:
bash variable capture stderr and stdout separately or get exit value
EDIT: Added sample code.
error=`osascript -e 'tell app "Finder" to adtivate' 2>&1`
echo $error
The above on my system captures the error messages.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With