且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在OS X中以编程方式获取正在运行的应用程序捆绑包

更新时间:2023-01-15 19:45:35

我找到了一种使用Swift和Cocoa API的方法.大概,使用普通C也应该可以,但这对于我的应用程序来说已经足够了.

I found a way to do it using Swift and Cocoa APIs. Presumably, this should also be possible using plain C, but this is good enough for my application.

import Foundation
import AppKit

// Get all running applications
let workspace = NSWorkspace.shared
let applications = workspace.runningApplications

for app in applications {
    print(app)
}

appNSApplication对象,并且具有捆绑标识符,这是我想知道的.

app is an NSApplication object, and that has a bundle identifier, which is what I wanted to know.