How to Programmatically Retrieve a List of Running Applications in OS X?

Barbara Streisand
Release: 2024-10-31 13:48:02
Original
971 people have browsed it

How to Programmatically Retrieve a List of Running Applications in OS X?

Detecting Running Applications in OS X Using System Calls

Question:

How can I programmatically retrieve a list of all currently running application bundles in OS X, including those displayed in the Dock or Activity Monitor?

Answer:

To obtain the desired information, utilize Cocoa APIs. The following Swift code sample provides an example:

<code class="swift">import Foundation
import AppKit

// Gather running applications
let workspace = NSWorkspace.shared
let applications = workspace.runningApplications

// Inspect each application
for app in applications {
    print(app)
}</code>
Copy after login

The app variable in this code represents an NSApplication object, which provides access to the bundle identifier, providing the information you seek.

The above is the detailed content of How to Programmatically Retrieve a List of Running Applications in OS X?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!