我是 AppleScript 的新手,但我必须重新创建一个我在 OSX 中为 Windows 编写的批处理文件,而 AppleScript 似乎是最好的方法。基本上,脚本将由另一个程序动态创建然后执行。AppleScript 只需要等待一个进程,我想通过它的进程 ID 来识别它,如果进程在特定时间后仍在运行,则显示一条消息。
这可能吗?如果可以,怎么做?
提前致谢
我是 AppleScript 的新手,但我必须重新创建一个我在 OSX 中为 Windows 编写的批处理文件,而 AppleScript 似乎是最好的方法。基本上,脚本将由另一个程序动态创建然后执行。AppleScript 只需要等待一个进程,我想通过它的进程 ID 来识别它,如果进程在特定时间后仍在运行,则显示一条消息。
这可能吗?如果可以,怎么做?
提前致谢
这里有一些东西(希望)让你上路:
在网上搜索了更多之后,我最终找到了解决我给定问题的方法。这是我用来检查具有给定 ID 的进程pid
是否正在运行的 AppleScript 代码
tell application "System Events"
set runningApplications to (unix id of every process)
if (runningApplications contains (pid as integer)) is false then
-- process is not running
else
-- process still running
end if
end tell
这显然只是一个片段。就我个人而言,我将上述语句放在一个repeat
循环中,但这提供了一种检查进程 ID(即unix id
)的解决方案。
希望这对其他人有帮助