Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AppleScript Runner exit status passed back to shell script

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!

like image 372
krill Avatar asked Nov 05 '22 23:11

krill


1 Answers

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.

like image 185
Clark Avatar answered Nov 11 '22 02:11

Clark