如何在Swift中获取NSAppleScript PID?

时间:2017-03-12 20:36:57

标签: swift macos cocoa applescript

我使用NSAppleScript启动了一个命令。如何获得该命令的PID?应用程序关闭后,我需要它立即关闭该过程。

1 个答案:

答案 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)")
    }
}