我有一个应用程序的两个实例在运行(相同的应用程序路径),我想通过它们的PID来确定其中一个实例的目标,以运行一个AppleScript代码片段。我该怎么做呢?我有我想要作为目标的实例的PID,但是如果我运行以下命令,它将在最后启动的任何实例上执行,而不管哪个实例是最前面的。
tell application "/Applications/Adobe After Effects CC 2018/Adobe After Effects CC 2018.app" to DoScript "alert()"有没有一种方法可以通过PID获取应用程序,并具体说明该应用程序?
谢谢!
发布于 2018-10-20 04:25:57
您需要列出为特定应用程序运行的进程。
一种方法是:
set theApp to "Adobe After Effects CC 2018"
tell application "System Events"
set processList to the name of every process whose name contains theApp
set {processList, pidList} to the {name, unix id} of (every process whose name contains theApp)
set frontmost of every process whose unix id is item 1 of pidList to true
display dialog "Application: " & item 1 of processList & "
PID: " & item 1 of pidList
end tell这应该根据它的PID切换到应用程序的第一个进程。将display dialog行替换为您希望在该点上发生的任何事情。
https://stackoverflow.com/questions/52898008
复制相似问题