Home > Article > Backend Development > How to Programmatically Retrieve Running Application Bundles in macOS?
Introduction:
Obtaining a list of running application bundles in macOS is essential for various scenarios such as time tracking, process monitoring, and parental controls. However, relying solely on sysctl() to retrieve running processes may not provide sufficient information about their associated application bundles.
Solution:
Leveraging Cocoa APIs in Swift offers an effective solution:
<code class="swift">import Foundation import AppKit // Get all running applications let workspace = NSWorkspace.shared let applications = workspace.runningApplications for app in applications { print(app) }</code>
This code retrieves the NSRunningApplication objects for each running application, which contain the desired bundle identifier.
Additional Considerations:
Implementation Benefits:
The above is the detailed content of How to Programmatically Retrieve Running Application Bundles in macOS?. For more information, please follow other related articles on the PHP Chinese website!