我想执行Applescript
命令,该命令检查某些进程是否崩溃,然后重新启动该应用程序。我已经有了脚本,但是现在我需要从c++
代码中调用它。
脚本是:
tell application "Activity Monitor" to run --We need to run Activity Monitor
tell application "System Events" to tell process "Activity Monitor"
tell radio button 1 of radio group 1 of group 1 of toolbar 1 of window 1 to click --Using the CPU View
tell outline 1 of scroll area 1 of window 1 -- working with the list
set notResponding to rows whose value of first static text contains "Not Responding" -- Looking for Not responding process
repeat with aProcess in notResponding
set pid to value of text field 5 of aProcess -- For each non responding process retrieve the PID
if pid is not "" then do shell script ("kill -9 " & pid) -- KILL the PID.
end repeat
end tell
end tell
最佳答案
您可以调用“osascript”,这是执行Apple脚本的命令行工具。使用内置的C“系统”命令来执行它。这听起来像是依赖于平台的黑客,确实如此!将代码包装到指定的类中应该是这样。
顺便说一句:使用AppleScript监听某些过程 Activity 是一种好方法吗?您可能可以使用内置的unix功能读取过程信息。考虑一下
关于c++ - 从C++程序执行Applescript,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23386394/