Class

NSRunningApplication

An object that can manipulate and provide information for a single instance of an app.

Declaration

@interface NSRunningApplication : NSObject

Overview

Some properties of an app are fixed, such as the bundle identifier. Other properties may vary over time, such as whether the app is hidden. Properties that vary can be observed with key-value observing, in which case the description comment for the method notes this capability.

Properties that vary over time are inherently race-prone. For example, a hidden app may unhide itself at any time. To ameliorate this, properties persist until the next turn of the main run loop in a common mode. For example, if you repeatedly poll an unhidden app for its hidden property without allowing the run loop to run, it will continue to return NO, even if the app hides, until the next turn of the run loop.

NSRunningApplication is thread safe, in that its properties are returned atomically. However, it is still subject to the main run loop policy described above. If you access an instance of NSRunningApplication from a background thread, be aware that its time-varying properties may change from under you as the main run loop runs (or not).

An NSRunningApplication instance remains valid after the app exits. However, most properties lose their significance, and some properties may not be available on a terminated application.

To access the list of all running apps, use the runningApplications method in NSWorkspace.

Topics

Getting Running Application Instances

+ runningApplicationWithProcessIdentifier:

Returns the running application with the given process identifier, or nil if no application has that pid.

+ runningApplicationsWithBundleIdentifier:

Returns an array of currently running applications with the specified bundle identifier.

currentApplication

Returns an NSRunningApplication representing this application.

Activating Applications

active

Indicates whether the application is currently frontmost.

- activateWithOptions:

Attempts to activate the application using the specified options.

activationPolicy

Indicates the activation policy of the application.

NSApplicationActivationPolicy

Activation policies (used by activationPolicy) that control whether and how an app may be activated.

Hiding and Unhiding Applications

- hide

Attempts to hide or the application.

- unhide

Attempts to unhide or the application.

hidden

Indicates whether the application is currently hidden.

Application Information

localizedName

Indicates the localized name of the application.

icon

Returns the icon for the receiver’s application.

bundleIdentifier

Indicates the CFBundleIdentifier of the application.

bundleURL

Indicates the URL to the application's bundle.

executableArchitecture

Indicates the executing processor architecture for the application.

executableURL

Indicates the URL to the application's executable.

launchDate

Indicates the date when the application was launched.

finishedLaunching

Indicates whether the receiver’s process has finished launching,

processIdentifier

Indicates the process identifier (pid) of the application.

ownsMenuBar

Returns whether the application owns the current menu bar.

Terminating Applications

- forceTerminate

Attempts to force the receiver to quit.

- terminate

Attempts to quit the receiver normally.

terminated

Indicates that the receiver’s application has terminated.

+ terminateAutomaticallyTerminableApplications

Terminates invisibly running applications as if triggered by system memory pressure.

Relationships

Inherits From

See Also

Application

NSApplication

An object that manages an app’s main event loop and resources used by all of that app’s objects.

NSApplicationDelegate

A set of methods that delegates of NSApplication objects can implement.

NSApplicationMain

Called by the main function to create and run the application.