Mac Developer Library

Developer

AppKit Framework Reference NSRunningApplication Class Reference

Options
Deployment Target:

On This Page
Language:

NSRunningApplication

NSRunningApplication is a class to manipulate and provide information for a single instance of an application. Only user applications are tracked; this does not provide information about every process on the system. More...

Inheritance


Conforms To


Import Statement


import AppKit @import AppKit;

Availability


Available in OS X v10.6 and later.
  • Returns the running application with the given process identifier, or nil if no application has that pid.

    Declaration

    Swift

    convenience init?(processIdentifier pid: pid_t)

    Objective-C

    + (instancetype)runningApplicationWithProcessIdentifier:(pid_t)pid

    Parameters

    pid

    The process identifier.

    Return Value

    An instance of NSRunningApplication for the specified pid, or nil if the application has no process identifier.

    Discussion

    Applications that do not have PIDs cannot be returned from this method.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.6 and later.

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

    Declaration

    Swift

    class func runningApplicationsWithBundleIdentifier(_ bundleIdentifier: String) -> [AnyObject]

    Objective-C

    + (NSArray *)runningApplicationsWithBundleIdentifier:(NSString *)bundleIdentifier

    Parameters

    bundleIdentifier

    The bundle identifier.

    Return Value

    An array of NSRunningApplications, or an empty array if no applications match the bundle identifier.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • Returns an NSRunningApplication representing this application.

    Declaration

    Swift

    class func currentApplication() -> Self!

    Objective-C

    + (instancetype)currentApplication

    Return Value

    An NSRunningApplication instance for the current application.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • active active Property

    Indicates whether the application is currently frontmost. (read-only)

    Declaration

    Swift

    var active: Bool { get }

    Objective-C

    @property(readonly, getter=isActive) BOOL active

    Discussion

    This property is observable using key-value observing.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • Attempts to activate the application using the specified options.

    Declaration

    Swift

    func activateWithOptions(_ options: NSApplicationActivationOptions) -> Bool

    Objective-C

    - (BOOL)activateWithOptions:(NSApplicationActivationOptions)options

    Parameters

    options

    The options to use when activating the application. See NSApplicationActivationOptions for the possible values.

    Return Value

    YEStrue if the application was activated successfully, otherwise NOfalse.

    Discussion

    This method will return NOfalse if the application has quit, or is not a type of application than can be activated.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • Indicates the activation policy of the application. (read-only)

    Declaration

    Swift

    var activationPolicy: NSApplicationActivationPolicy { get }

    Objective-C

    @property(readonly) NSApplicationActivationPolicy activationPolicy

    Discussion

    The value returned by this property is usually fixed, but it may change through a call to activateWithOptions:.

    This property is observable using key-value observing.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • Attempts to hide or the application.

    Declaration

    Swift

    func hide() -> Bool

    Objective-C

    - (BOOL)hide

    Return Value

    YEStrue if the application was successfully hidden, otherwise NOfalse.

    Discussion

    The property of this value will be NOfalse if the application has already quit, or if of a type that is unable to be hidden.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • Attempts to unhide or the application.

    Declaration

    Swift

    func unhide() -> Bool

    Objective-C

    - (BOOL)unhide

    Return Value

    YEStrue if the application was successfully shown, otherwise NOfalse.

    Discussion

    The property of this value will be NOfalse if the application has already quit, or if of a type that is unable to be hidden.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.6 and later.

    See Also

    – hide
    hidden

  • hidden hidden Property

    Indicates whether the application is currently hidden. (read-only)

    Declaration

    Swift

    var hidden: Bool { get }

    Objective-C

    @property(readonly, getter=isHidden) BOOL hidden

    Discussion

    This property is observable using key-value observing.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • Indicates the localized name of the application. (read-only)

    Declaration

    Swift

    var localizedName: String? { get }

    Objective-C

    @property(readonly, copy) NSString *localizedName

    Discussion

    The value of this property is dependent on the current localization of the application and is suitable for presentation to the user.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • icon icon Property

    Returns the icon for the receiver’s application. (read-only)

    Declaration

    Swift

    var icon: NSImage? { get }

    Objective-C

    @property(readonly, strong) NSImage *icon

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • Indicates the CFBundleIdentifier of the application. (read-only)

    Declaration

    Swift

    var bundleIdentifier: String? { get }

    Objective-C

    @property(readonly, copy) NSString *bundleIdentifier

    Discussion

    The value of this property will be nil if the application does not have an Info.plist.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • bundleURL bundleURL Property

    Indicates the URL to the application's bundle. (read-only)

    Declaration

    Swift

    @NSCopying var bundleURL: NSURL? { get }

    Objective-C

    @property(readonly, copy) NSURL *bundleURL

    Discussion

    The value of this property is nil of the application does not have a bundle structure.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.6 and later.

    See Also

    executableURL

  • Indicates the executing processor architecture for the application. (read-only)

    Declaration

    Swift

    var executableArchitecture: Int { get }

    Objective-C

    @property(readonly) NSInteger executableArchitecture

    Discussion

    The returned value will be one of the constants in Mach-O Architecture in NSBundle Class Reference.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.6 and later.

    See Also

    executableURL

  • Indicates the URL to the application's executable. (read-only)

    Declaration

    Swift

    @NSCopying var executableURL: NSURL? { get }

    Objective-C

    @property(readonly, copy) NSURL *executableURL

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • Indicates the date when the application was launched. (read-only)

    Declaration

    Swift

    @NSCopying var launchDate: NSDate? { get }

    Objective-C

    @property(readonly, copy) NSDate *launchDate

    Discussion

    This property is only available for applications that were launched by LaunchServices.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • Indicates whether the receiver’s process has finished launching, (read-only)

    Declaration

    Swift

    var finishedLaunching: Bool { get }

    Objective-C

    @property(readonly, getter=isFinishedLaunching) BOOL finishedLaunching

    Discussion

    The value of this property corresponds to the running application having received an NSApplicationDidFinishLaunchingNotification notification internally. Some applications do not post this notification (applications that do not rely on NSApplication) and so are never reported as finished launching.

    This property is observable using key-value observing.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • Indicates the process identifier (pid) of the application. (read-only)

    Declaration

    Swift

    var processIdentifier: pid_t { get }

    Objective-C

    @property(readonly) pid_t processIdentifier

    Discussion

    Not all applications have a pid. Applications without a pid return a value of -1.

    Do not rely on this for comparing processes, instead compare NSRunningApplication instances using isEqual:.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • Returns whether the application owns the current menu bar. (read-only)

    Declaration

    Swift

    var ownsMenuBar: Bool { get }

    Objective-C

    @property(readonly) BOOL ownsMenuBar

    Discussion

    This property is observable using key-value observing.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.7 and later.

  • Attempts to force the receiver to quit.

    Declaration

    Swift

    func forceTerminate() -> Bool

    Objective-C

    - (BOOL)forceTerminate

    Return Value

    Returns YEStrue if the application successfully terminated, otherwise NOfalse.

    Discussion

    This method will return NOfalse if the application is no longer running when the forceTerminate message is sent to the receiver.

    This method may return before the receiver exits; you should observe the terminated property to determine when the application terminates.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • Attempts to quit the receiver normally.

    Declaration

    Swift

    func terminate() -> Bool

    Objective-C

    - (BOOL)terminate

    Return Value

    Returns YEStrue if the request was successfully sent, otherwise NOfalse.

    Discussion

    This method will return NOfalse if the application is no longer running when the terminate message is sent to the receiver.

    This method may return before the receiver exits; you should observe the terminated property to determine when the application terminates.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.6 and later.

    See Also

    terminated

  • Indicates that the receiver’s application has terminated. (read-only)

    Declaration

    Swift

    var terminated: Bool { get }

    Objective-C

    @property(readonly, getter=isTerminated) BOOL terminated

    Discussion

    The value of terminated is YEStrue if the receiver’s application has terminated, otherwise NOfalse.

    This property is observable using key-value observing.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.6 and later.

    See Also

    – terminate

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

    Declaration

    Swift

    class func terminateAutomaticallyTerminableApplications()

    Objective-C

    + (void)terminateAutomaticallyTerminableApplications

    Discussion

    This method is intended for installer applications and similar applications to ensure that nothing is unexpectedly relying on the files they're replacing.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.7 and later.

  • The following flags are for activateWithOptions:.

    Declaration

    Swift

    struct NSApplicationActivationOptions : RawOptionSetType { init(_ rawValue: UInt) init(rawValue rawValue: UInt) static var ActivateAllWindows: NSApplicationActivationOptions { get } static var ActivateIgnoringOtherApps: NSApplicationActivationOptions { get } }

    Objective-C

    enum { NSApplicationActivateAllWindows = 1 << 0, NSApplicationActivateIgnoringOtherApps = 1 << 1 }; typedef NSUInteger NSApplicationActivationOptions;

    Constants

    • ActivateAllWindows

      NSApplicationActivateAllWindows

      By default, activation brings only the main and key windows forward. If you specify NSApplicationActivateAllWindows, all of the application's windows are brought forward.

      Available in OS X v10.6 and later.

    • ActivateIgnoringOtherApps

      NSApplicationActivateIgnoringOtherApps

      By default, activation deactivates the calling app (assuming it was active), and then the new app is activated only if there is no currently active application. This prevents the new app from stealing focus from the user, if the app is slow to activate and the user has switched to a different app in the interim. However, if you specify NSApplicationActivateIgnoringOtherApps, the application is activated regardless of the currently active app, potentially stealing focus from the user. You should rarely pass this flag because stealing key focus produces a very bad user experience.

      Available in OS X v10.6 and later.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • The following activation policies control whether and how an application may be activated. They are used by activationPolicy.

    Declaration

    Swift

    enum NSApplicationActivationPolicy : Int { case Regular case Accessory case Prohibited }

    Objective-C

    enum { NSApplicationActivationPolicyRegular, NSApplicationActivationPolicyAccessory, NSApplicationActivationPolicyProhibited }; typedef NSInteger NSApplicationActivationPolicy;

    Constants

    • Regular

      NSApplicationActivationPolicyRegular

      The application is an ordinary app that appears in the Dock and may have a user interface. This is the default for bundled apps, unless overridden in the Info.plist.

      Available in OS X v10.6 and later.

    • Accessory

      NSApplicationActivationPolicyAccessory

      The application does not appear in the Dock and does not have a menu bar, but it may be activated programmatically or by clicking on one of its windows. This corresponds to value of the LSUIElement key in the application’s Info.plist being 1.

      Available in OS X v10.6 and later.

    • Prohibited

      NSApplicationActivationPolicyProhibited

      The application does not appear in the Dock and may not create windows or be activated. This corresponds to the value of the LSBackgroundOnly key in the application’s Info.plist being 1. This is also the default for unbundled executables that do not have Info.plists.

      Available in OS X v10.6 and later.

    Import Statement

    import AppKit

    Availability

    Available in OS X v10.6 and later.