【发布时间】:2020-08-26 00:20:59
【问题描述】:
我真的是 applescript 的新手,如果你能就我的问题给我建议,那肯定会很有帮助。
我目前正在尝试使用脚本编辑器创建一个脚本,该脚本可以检查 Google Chrome 的当前 CPU 使用率是否超过 50%。但是,我不确定测试的返回值是整数形式还是字符串形式。我在将“测试”与特定数字进行比较时遇到问题。你能帮忙检查一下我做错了什么吗?谢谢你。这是我当前完整的applescript,它会无限期运行,直到Google Chrome CPU 使用率达到50%(这里的主要问题是我不确定比较测试
getProcessPercentCPU("Google Chrome")
on getProcessPercentCPU(someProcess)
set test to do shell script "/bin/ps -xco %cpu,command | /usr/bin/awk '/" & someProcess & "$/ {print $1}'"
repeat while test < "50.0"
set test to do shell script "/bin/ps -xco %cpu,command | /usr/bin/awk '/" & someProcess & "$/ {print $1}'"
end repeat
display dialog test
end getProcessPercentCPU
如果“测试”达到 50.0 或更高,该脚本应该会显示一个对话框。但是,对话框中的返回值不准确或不是 50 或更大。请帮忙。
提前感谢您的帮助!
【问题讨论】:
标签: applescript