我使用NSAppleScript
启动了一个命令。如何获得该命令的PID?应用程序关闭后,我需要它立即关闭该过程。
答案 0 :(得分:2)
查看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)")
}
}