kri*_*ill 5 macos bash shell applescript osascript
我需要能够在Shell脚本中运行AppleScript。我正在使用“ AppleScript Runner”以便处于交互模式,因此支持对话框等。我已经工作了,但是我需要将AppleScript Runner应用程序的退出状态返回到外壳程序,以便我可以查看脚本中是否有任何错误。
这是我的shell脚本:
output=$(/usr/bin/osascript << EOT
tell application "AppleScript Runner"
do script "somescript.scpt"
end
EOT)
status=$?
Run Code Online (Sandbox Code Playgroud)
在这里,我的变量$ status仅以osascript命令的退出状态结束(无论somescript.scpt是否成功成功运行,其退出状态均为0),而不是应用程序AppleScript Runner的退出状态。
有人知道我该怎么做吗?
谢谢!
-e 标志将错误打印到 stderr,并且是默认设置。所以你只需要阅读stderr即可。
如果您对此不熟悉,这个答案可能会对您有所帮助:
编辑:添加示例代码。
error=`osascript -e 'tell app "Finder" to adtivate' 2>&1`
echo $error
Run Code Online (Sandbox Code Playgroud)
我的系统上的上述内容捕获了错误消息。