开发者

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开发者_如何学JAVA 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜