1
我试图从AppleScript启动控制台程序并在崩溃时重新启动。我写了这个代码从AppleScript启动控制台程序并监视其状态
repeat
do shell script "/path/to/program"
end repeat
但它挂起和mac无法重新启动。 我怎样才能把“做外壳脚本”在另一个线程?
我试图从AppleScript启动控制台程序并在崩溃时重新启动。我写了这个代码从AppleScript启动控制台程序并监视其状态
repeat
do shell script "/path/to/program"
end repeat
但它挂起和mac无法重新启动。 我怎样才能把“做外壳脚本”在另一个线程?
您只需在命令末尾加上一个“&”字符即可。这将它发送到后台。但是我不会使用你的代码。重复循环将永远运行,并且只要运行就产生新的进程。你最好的选择是运行一个保持开放的applescript,定期检查过程是否正在运行。如果不是,那么苹果电脑可以启动它。重复循环不是你想要的。试试这个代码。将其保存为应用程序,并在保存窗口中选中保留打开的对话框。
on run
end run
on idle
set runShellScript to false
tell application "System Events"
if not (exists process "processName") then
set runShellScript to true
end if
end tell
if runShellScript then do shell script "/path/to/program &"
return 30 -- the script will stop for 30 seconds then run again until you quit the applescript
end idle