我用NSAppleScript
启动了一个命令。我怎样才能得到那个命令的PID?应用程序一关闭,我就需要它来关闭进程。
最佳答案
看看runningApplications
API of NSWorkspace。例如:
let runningApplications = NSWorkspace.shared().runningApplications
for eachApplication in runningApplications {
if let applicationName = eachApplication.localizedName {
print("application is \(applicationName) & pid is \(eachApplication.processIdentifier)")
}
}