从c++程序执行Applescript
Execute Applescript from c++ program
我想执行一个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",这是一个执行苹果脚本的命令行工具。使用内置的C"system"命令来执行它。这听起来可能像是一个依赖于平台的黑客攻击,事实确实如此!将代码封装到指定的类中应该是一种方法。
顺便问一下:使用AppleScript听一些流程活动是个好方法吗?您可能能够使用内置的unix功能读取进程信息。想想看
相关文章:
- 在执行其他功能的同时播放动画(LED矩阵和Arduino/ESP8266)
- C++,系统无法执行指定的程序
- 使用C++中的模板和运算符重载执行矩阵运算
- 创建一个函数以在输入为负数或零时输出字符串.第一次执行用户定义的函数
- 执行函数时导致崩溃的变量
- 无论条件是否为true,if总是在c++中执行
- 当函数模板参数是具有默认参数的类模板时,函数模板参数的推导如何执行
- 在C++中对T*类型执行std::move的意外行为
- 使用QProcess执行命令,并将结果存储在QStringList中
- 如何在没有信号的情况下从C++执行QML插槽
- 如何确认我的constexpr表达式实际上已经在编译时执行
- C++17中的并行执行策略
- QML按钮点击功能执行顺序
- 程序在执行程序的其余部分之前退出
- 为什么catch中的代码没有被执行
- C++从其他 constexpr 创建 lambda 不能按顺序执行 Constexpr
- 将执行、作业和WinAPI相乘
- 对字符数组中的元素执行逐位操作
- 如何从C++程序中执行一个简单的Applescript
- 从c++程序执行Applescript