5

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!

krill
  • 199
  • 5

1 Answers1

2

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.

Community
  • 1
  • 1
Clark
  • 833
  • 4
  • 6
  • I seem to be only getting the error messages in stdout and not stderr with this setup. I have used "set -e" in my shell script as well. – krill Apr 11 '11 at 21:00
  • I just tested a short script on my system and it's going to stderr. – Clark Apr 11 '11 at 22:55