我有一个运行的应用程序的2个实例(相同的应用程序路径),我想通过其PID定位其中一个以运行AppleScript代码段。我将如何处理?我具有要定位的实例的PID,但是如果运行以下命令,它将在最后启动的那个实例上执行,无论哪个实例在最前面。
tell application "/Applications/Adobe After Effects CC 2018/Adobe After Effects CC 2018.app" to DoScript "alert()"
有没有一种方法可以通过PID来获取申请并具体告知该申请?
谢谢!
答案 0 :(得分:0)
您需要列出特定应用程序正在运行的进程的列表。
一种方法是:
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
行替换为此时要发生的任何情况。