"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How to get a list of active apps in OS X?

How to get a list of active apps in OS X?

Posted on 2025-05-02
Browse:938

How to Retrieve a List of Active Applications in OS X?

Identifying Active Applications in OS X

Question:

Obtain a list of active application bundles, especially GUI applications that the user has initiated, with information beyond the process names.

Answer:

Utilizing Apple's Swift and Cocoa frameworks, it is possible to programmatically retrieve a list of running applications in OS X.

import Foundation
import AppKit

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

for app in applications {
    print(app)
}

The resulting app object is an NSApplication instance that contains the necessary information, including the desired bundle identifier.

Implementation Details:

  • The NSWorkspace class provides access to system-level information about running applications.
  • The runningApplications property returns an array of NSApplication instances representing active applications.
  • Each NSApplication instance contains a bundleIdentifier property that uniquely identifies the application bundle.

Additional Notes:

  • This approach is specific to OS X and utilizes Objective-C and Swift code.
  • Similar functionality may be achievable using lower-level C APIs, but the above solution proves sufficient for most scenarios.
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3