Mac Developer Library

Developer

AppKit Framework Reference NSWorkspace Class Reference

Options
Deployment Target:

On This Page
Language:

NSWorkspace

An NSWorkspace object responds to app requests to perform a variety of services:

  • Opening, manipulating, and obtaining information about files and devices

  • Tracking changes to the file system, devices, and the user database

  • Getting and setting Finder information for files.

  • Launching apps

There is one shared NSWorkspace object per app. You use the class method sharedWorkspace to access it. For example, the following statement uses an NSWorkspace object to request that a file be opened in the TextEdit app:

  • [[NSWorkspace sharedWorkspace] openFile:@"/Myfiles/README"
  • withApplication:@"TextEdit"];

Inheritance


Conforms To


Import Statement


Swift

import AppKit

Objective-C

@import AppKit;

Availability


Available in OS X v10.0 and later.
  • Returns the shared NSWorkspace instance.

    Declaration

    Swift

    class func sharedWorkspace() -> NSWorkspace

    Objective-C

    + (NSWorkspace *)sharedWorkspace

    Return Value

    The NSWorkspace object associated with the process.

    Discussion

    It is safe to call this method from any thread in your app.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the notification center for workspace notifications.

    Declaration

    Swift

    var notificationCenter: NSNotificationCenter { get }

    Objective-C

    @property(readonly, strong) NSNotificationCenter *notificationCenter

    Return Value

    The notification center object.

    Discussion

    It is safe to call this method from any thread in your app in OS X v10.6 and later.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Opens the location at the specified URL.

    Declaration

    Swift

    func openURL(_ url: NSURL) -> Bool

    Objective-C

    - (BOOL)openURL:(NSURL *)url

    Parameters

    url

    A URL specifying the location to open.

    Return Value

    YEStrue if the location was successfully opened; otherwise, NOfalse.

    Discussion

    It is safe to call this method from any thread in OS X v10.6 and later.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Opens the specified file specified using the default app associated with its type.

    Declaration

    Swift

    func openFile(_ fullPath: String) -> Bool

    Objective-C

    - (BOOL)openFile:(NSString *)fullPath

    Parameters

    fullPath

    The full path to the file.

    Return Value

    YEStrue if the file was successfully opened; otherwise, NOfalse.

    Discussion

    The sending app is deactivated before the request is sent.

    It is safe to call this method from any thread in your app in OS X v10.6 and later.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Opens a file using the specified app.

    Declaration

    Swift

    func openFile(_ fullPath: String, withApplication appName: String) -> Bool

    Objective-C

    - (BOOL)openFile:(NSString *)fullPath withApplication:(NSString *)appName

    Parameters

    fullPath

    The full path to the file.

    appName

    The name of the app to use when opening the file.

    Return Value

    YEStrue if the file was successfully opened; otherwise, NOfalse.

    Discussion

    The appName parameter need not be specified with a full path and, in the case of an app wrapper, may be specified with or without the .app extension, as described in Use of .app Extension. The sending app is deactivated before the request is sent.

    It is safe to call this method from any thread in your app in OS X v10.6 and later.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Opens the specified file and optionally deactivates the sending app.

    Declaration

    Swift

    func openFile(_ fullPath: String, withApplication appName: String, andDeactivate flag: Bool) -> Bool

    Objective-C

    - (BOOL)openFile:(NSString *)fullPath withApplication:(NSString *)appName andDeactivate:(BOOL)flag

    Parameters

    fullPath

    The full path to the file.

    appName

    The name of the app to use when opening the file.

    flag

    If YES, the sending app is deactivated before the request is sent, allowing the opening app to become the active app.

    Return Value

    YEStrue if the file was successfully opened; otherwise, NOfalse.

    Discussion

    The appName parameter need not be specified with a full path and, in the case of an app wrapper, may be specified with or without the .app extension, as described in Use of .app Extension. If appName is nil, the default app for the file’s type is used.

    It is safe to call this method from any thread in your app in OS X v10.6 and later.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Opens a file using the default app for its type and animates the action using a custom icon.

    Declaration

    Swift

    func openFile(_ fullPath: String, fromImage anImage: NSImage!, at point: NSPoint, inView aView: NSView!) -> Bool

    Objective-C

    - (BOOL)openFile:(NSString *)fullPath fromImage:(NSImage *)anImage at:(NSPoint)point inView:(NSView *)aView

    Parameters

    fullPath

    The full path to the file.

    anImage

    The icon for the file.

    point

    The point in aView at which to display the icon.

    aView

    The view in which to display the icon.

    Return Value

    YEStrue if the file was successfully opened; otherwise, NOfalse.

    Discussion

    Use of this method is discouraged. The method currently provides the same behavior as the openFile: method.The Finder provides an animation before opening the file to give the user feedback that the file is to be opened. To provide this animation, anImage should contain an icon for the file, and its image should be displayed at point, specified in the coordinates of aView.

    The sending app is deactivated before the request is sent.

    It is safe to call this method from any thread in your app in OS X v10.6 and later.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Launches the specified app.

    Declaration

    Swift

    func launchApplication(_ appName: String) -> Bool

    Objective-C

    - (BOOL)launchApplication:(NSString *)appName

    Parameters

    appName

    The name of the app to open.

    Return Value

    YEStrue if the app was successfully launched or was already running; otherwise, NOfalse.

    Discussion

    The appName parameter need not be specified with a full path and, in the case of an app wrapper, may be specified with or without the .app extension, as described in Use of .app Extension.

    Before this method begins, it posts an NSWorkspaceWillLaunchApplicationNotification to the NSWorkspace object’s notification center. When the operation is complete, it posts an NSWorkspaceDidLaunchApplicationNotification.

    It is safe to call this method from any thread in your app in OS X v10.6 and later.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Launches the specified app using additional options.

    Declaration

    Swift

    func launchApplication(_ appName: String, showIcon showIcon: Bool, autolaunch autolaunch: Bool) -> Bool

    Objective-C

    - (BOOL)launchApplication:(NSString *)appName showIcon:(BOOL)showIcon autolaunch:(BOOL)autolaunch

    Parameters

    appName

    The name of the app to open.

    showIcon

    If NOfalse, the app's icon is not placed on the screen. (The icon still exists, though.)

    autolaunch

    If YEStrue, the autolaunch default is set as though the specified app were autolaunched at startup.

    Return Value

    YEStrue if the app was successfully launched or was already running; otherwise, NOfalse.

    Discussion

    Use of this method is discouraged. Its current behavior is the same as the launchApplication: method.

    Returns YEStrue if the app is successfully launched or already running, and NOfalse if it can’t be launched.

    Before this method begins, it posts an NSWorkspaceWillLaunchApplicationNotification to the NSWorkspace object’s notification center. When the operation is complete, it posts an NSWorkspaceDidLaunchApplicationNotification.

    It is safe to call this method from any thread in your app in OS X v10.6 and later.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Launches the app at the specified URL.

    Declaration

    Swift

    func launchApplicationAtURL(_ url: NSURL, options options: NSWorkspaceLaunchOptions, configuration configuration: [NSObject : AnyObject], error error: NSErrorPointer) -> NSRunningApplication?

    Objective-C

    - (NSRunningApplication *)launchApplicationAtURL:(NSURL *)url options:(NSWorkspaceLaunchOptions)options configuration:(NSDictionary *)configuration error:(NSError **)error

    Parameters

    url

    The application URL.

    options

    Options to use when launching the application. See NSWorkspaceLaunchOptions for possible values.

    configuration

    A dictionary containing the configuration options. Possible key-value pairs are described in Workspace Launch Configuration Options

    error

    Returns, by-reference, the error if the application was unable to be launched. You may specify nil for this parameter if you do not want the error information.

    Return Value

    If the app is already running, and NSWorkspaceLaunchNewInstance is not specified in the options dictionary, then a reference to the existing app is returned; otherwise a new application reference is returned. The the application could not be launched nil is returned, and the error is specified in error.

    Discussion

    The configuration dictionary can be used to pass additional options to the app. If the dictionary is nil, in which case default behavior applies.

    It is safe to call this method from any thread in your app in OS X v10.6 and later.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • Hides all applications other than the sender.

    Declaration

    Swift

    func hideOtherApplications()

    Objective-C

    - (void)hideOtherApplications

    Discussion

    The user can hide all apps except the current one by Command-Option-clicking on an app’s Dock icon.

    This method must be called from your app’s main thread.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Duplicates the specified URLS asynchronously in the same manner as the Finder.

    Declaration

    Swift

    func duplicateURLs(_ URLs: [AnyObject], completionHandler completionHandler: (([NSObject : AnyObject]!, NSError!) -> Void)?)

    Objective-C

    - (void)duplicateURLs:(NSArray *)URLs completionHandler:(void (^)(NSDictionary *newURLs, NSError *error))completionHandler

    Parameters

    URLs

    An array of NSURL objects representing the files to duplicate. This parameter must not be nil.

    completionHandler

    The completion handler block object to call when the operation completes. You may specify nil for this parameter. If this parameter is not nil, you must call the duplicateURLs:completionHandler: method from a block running on an active dispatch queue; your completion handler block is subsequently executed on the same dispatch queue.

    This block takes two parameters:

    newURLs

    A dictionary parameter whose keys and values are NSURL objects. Each key is a URL from the URLs parameter. The value of each key is a URL representing the location of the duplicated file. If this method could not duplicate a file, the corresponding URL is not included in the dictionary.

    error

    If the operation succeeded for every file, this parameter is nil. If the operation failed for one or more files, the parameter contains an error object describing the overall result of the operation in a manner suitable for presentation to the user.

    Discussion

    This method may cause a progress indicator, or other user interface element, to be shown by the Finder.

    In OS X v10.6, this method requires that the main run loop be run in a common mode. It is safe to call this method from any thread of your app.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • Moves the specified URLs to the trash in the same manner as the Finder.

    Declaration

    Swift

    func recycleURLs(_ URLs: [AnyObject], completionHandler handler: (([NSObject : AnyObject]!, NSError!) -> Void)?)

    Objective-C

    - (void)recycleURLs:(NSArray *)URLs completionHandler:(void (^)(NSDictionary *newURLs, NSError *error))handler

    Parameters

    URLs

    An array of NSURL objects representing the files to move to the trash. This parameter must not be nil

    handler

    The completion handler block object to call when the operation completes. You may specify nil for this parameter. If this parameter is not nil, you must call the recycleURLs:completionHandler: method from a block running on an active dispatch queue; your completion handler block is subsequently executed on the same dispatch queue.

    The block takes two arguments:

    newURLs

    A dictionary parameter whose keys and values are NSURL objects. Each key is a URL from the URLs parameter. The value of each key is a URL representing the location of the file in the trash. If this method could not move a file to the trash, the corresponding URL is not included in the dictionary.

    error

    If the operation succeeded for every file, this parameter is nil. If the operation failed for one or more files, the parameter contains an error object describing the overall result of the operation in a manner suitable for presentation to the user.

    Discussion

    This method may cause a progress indicator, or other user interface element, to be shown by the Finder.

    In OS X v10.6, this method requires that the main run loop be run in a common mode to facilitate the display of any user interface elements. It is safe to call this method from any thread of your app.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • Performs a file operation on a set of files in a particular directory.

    Declaration

    Swift

    func performFileOperation(_ operation: String, source source: String, destination destination: String, files files: [AnyObject], tag tag: UnsafeMutablePointer<Int>) -> Bool

    Objective-C

    - (BOOL)performFileOperation:(NSString *)operation source:(NSString *)source destination:(NSString *)destination files:(NSArray *)files tag:(NSInteger *)tag

    Parameters

    operation

    The file operation to perform. The possible values for this parameter are described in File Operations.

    source

    The full path to the directory containing the files on which to operate.

    destination

    The full path to the destination directory of the operation.

    files

    An array of NSString objects specifying the names of the files and directories to be manipulated. Each string must not contain any path information other than the name of the file or directory. In other words, all of the files and directories must be located in the source directory and not in one if its subdirectories.

    tag

    On input, a integer variable; on return, this variable contains a negative integer if the operation fails, 0 if the operation was performed synchronously and succeeded, or a positive integer if the operation was performed asynchronously. If the value is a positive integer, the value is a tag that identifies the requested file operation.

    Return Value

    YEStrue if the operation succeeded; otherwise, NOfalse.

    Discussion

    Some operations—such as moving, copying, and linking files—require a destination directory to be specified. If not, destination should be the empty string (@""). Before this method returns, it posts an NSWorkspaceDidPerformFileOperationNotification to the NSWorkspace object's notification center.

    It is safe to call this method from any thread of your app.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Activates the Finder, and opens one or more windows selecting the specified files.

    Declaration

    Swift

    func activateFileViewerSelectingURLs(_ fileURLs: [AnyObject])

    Objective-C

    - (void)activateFileViewerSelectingURLs:(NSArray *)fileURLs

    Parameters

    fileURLs

    The files to select and display in the Finder.

    Discussion

    It is safe to call this method from any thread of your app.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • Selects the file specified by fullPath.

    Declaration

    Swift

    func selectFile(_ fullPath: String, inFileViewerRootedAtPath rootFullPath: String) -> Bool

    Objective-C

    - (BOOL)selectFile:(NSString *)fullPath inFileViewerRootedAtPath:(NSString *)rootFullPath

    Parameters

    fullPath

    The full path of the file to select.

    rootFullPath

    If a path is specified, a new file viewer is opened. If you specify an empty string (@"") for this parameter, the file is selected in the main viewer.

    Return Value

    YEStrue if the file was successfully selected; otherwise, NOfalse.

    Discussion

    In OS X v10.5 and later, this method does not follow symlinks when selecting the file. If the fullPath parameter contains any symlinks, this method selects the symlink instead of the file it targets. If you want to select the target file, use the stringByResolvingSymlinksInPath method to resolve any symlinks before calling this method.

    It is safe to call this method from any thread of your app.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the uniform type identifier of the specified file, if it can be determined..

    Declaration

    Swift

    func typeOfFile(_ absoluteFilePath: String, error outError: NSErrorPointer) -> String?

    Objective-C

    - (NSString *)typeOfFile:(NSString *)absoluteFilePath error:(NSError **)outError

    Parameters

    absoluteFilePath

    The absolute path of the file.

    outError

    If the Uniform Type Identifier of the file at absolutePath can’t be determined, outError contains an NSError object that describes why.

    Return Value

    An NSString containing the uniform type identifier of the file at absoluteFilePath. If no UTI can be determined the return value is nil.

    Discussion

    If the file at the specified path is a symbolic link, the type of the symbolic link is returned.

    It is safe to call this method from any thread of your app.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • Returns the localized description for the specified Uniform Type Identifier

    Declaration

    Swift

    func localizedDescriptionForType(_ typeName: String) -> String?

    Objective-C

    - (NSString *)localizedDescriptionForType:(NSString *)typeName

    Parameters

    typeName

    A string containing the Uniform Type Identifier.

    Return Value

    An NSString containing the localized description of typeName.

    Discussion

    The localized description is suitable for displaying to the user.

    It is safe to call this method from any thread of your app.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • Returns the preferred filename extension for the specified Uniform Type Identifier.

    Declaration

    Swift

    func preferredFilenameExtensionForType(_ typeName: String) -> String?

    Objective-C

    - (NSString *)preferredFilenameExtensionForType:(NSString *)typeName

    Parameters

    typeName

    A string containing the Uniform Type Identifier.

    Return Value

    The appropriate filename extension for typeName, or nil if no extension could be determined.

    Discussion

    It is safe to call this method from any thread of your app.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • Returns whether the specified filename extension is appropriate for the Uniform Type Identifier.

    Declaration

    Swift

    func filenameExtension(_ filenameExtension: String, isValidForType typeName: String) -> Bool

    Objective-C

    - (BOOL)filenameExtension:(NSString *)filenameExtension isValidForType:(NSString *)typeName

    Parameters

    filenameExtension

    A string containing the filename extension.

    typeName

    A string containing the Uniform Type Identifier.

    Return Value

    YEStrue if fileNameExtension is a valid extension for typeName, NOfalse otherwise

    Discussion

    It is safe to call this method from any thread of your app.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • Returns a Boolean indicating that the first Uniform Type Identifier conforms to the second Uniform Type Identifier.

    Declaration

    Swift

    func type(_ firstTypeName: String, conformsToType secondTypeName: String) -> Bool

    Objective-C

    - (BOOL)type:(NSString *)firstTypeName conformsToType:(NSString *)secondTypeName

    Parameters

    firstTypeName

    A string containing the Uniform Type Identifier that should conform to secondTypeName.

    secondTypeName

    A string containing a Uniform Type Identifier.

    Return Value

    YEStrue if firstTypeName conforms to the uniform type identifier hierarchy of secondTypeName, NOfalse otherwise.

    Discussion

    Use this method instead of comparing Uniform Identifier Types for equality. See Uniform Type Identifiers Overview for information about Uniform Type Identifier conformance.

    This method will always return YEStrue if the two strings are equal. It is appropriate to use this method with other type names, including those declared in CFBundleTypeName Info.plist entries.

    It is safe to call this method from any thread of your app.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.5 and later.

  • Returns the URL for the app with the specified identifier.

    Declaration

    Swift

    func URLForApplicationWithBundleIdentifier(_ bundleIdentifier: String) -> NSURL?

    Objective-C

    - (NSURL *)URLForApplicationWithBundleIdentifier:(NSString *)bundleIdentifier

    Parameters

    bundleIdentifier

    A bundle identifier specifying an app.

    Return Value

    The URL of the app, or nil if no app has the bundle identifier.

    Discussion

    This uses various (currently unspecified) heuristics in case multiple apps have the same bundle ID.

    It is safe to call this method from any thread of your app.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • Retrieves information about the specified file.

    Declaration

    Swift

    func getInfoForFile(_ fullPath: String, application appName: AutoreleasingUnsafeMutablePointer<NSString?>, type type: AutoreleasingUnsafeMutablePointer<NSString?>) -> Bool

    Objective-C

    - (BOOL)getInfoForFile:(NSString *)fullPath application:(NSString **)appName type:(NSString **)type

    Parameters

    fullPath

    The full path to the desired file.

    appName

    The app the system would use to open the file.

    type

    On input, a pointer to a string object variable; on return, if the method is successful, this variable contains a string object with the filename extension or encoded HFS file type of the file.

    Return Value

    YEStrue if the information was retrieved successfully; otherwise, NOfalse if the file could not be found or the app was not associated with the file.

    Discussion

    It is safe to call this method from any thread of your app.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the URL to the default app that would be used to open the given URL.

    Declaration

    Swift

    func URLForApplicationToOpenURL(_ url: NSURL) -> NSURL?

    Objective-C

    - (NSURL *)URLForApplicationToOpenURL:(NSURL *)url

    Parameters

    url

    The URL of the file to open.

    Return Value

    The URL of the default app that would open the specified url. Returns nil if no app is able to open the url, or if the file url does not exist.

    Discussion

    This is the programmatic equivalent of double clicking a document in the Finder.

    It is safe to call this method from any thread of your app.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • Returns the full path for the specified app.

    Declaration

    Swift

    func fullPathForApplication(_ appName: String) -> String?

    Objective-C

    - (NSString *)fullPathForApplication:(NSString *)appName

    Parameters

    appName

    The name of the app.

    Return Value

    The full path for the app, or nil if the specified app was not found.

    Discussion

    It is safe to call this method from any thread of your app.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Describes the file system at fullPath.

    Declaration

    Swift

    func getFileSystemInfoForPath(_ fullPath: String, isRemovable removableFlag: UnsafeMutablePointer<ObjCBool>, isWritable writableFlag: UnsafeMutablePointer<ObjCBool>, isUnmountable unmountableFlag: UnsafeMutablePointer<ObjCBool>, description description: AutoreleasingUnsafeMutablePointer<NSString?>, type fileSystemType: AutoreleasingUnsafeMutablePointer<NSString?>) -> Bool

    Objective-C

    - (BOOL)getFileSystemInfoForPath:(NSString *)fullPath isRemovable:(BOOL *)removableFlag isWritable:(BOOL *)writableFlag isUnmountable:(BOOL *)unmountableFlag description:(NSString **)description type:(NSString **)fileSystemType

    Parameters

    fullPath

    The path to the file-system mount point.

    removableFlag

    On input, a boolean variable; on return, this variable contains YEStrue if the file system is on removable media.

    writableFlag

    On input, a boolean variable; on return, this variable contains YEStrue if the file system writable.

    unmountableFlag

    On input, a boolean variable; on return, this variable contains YEStrue if the file system is unmountable.

    description

    On input, a pointer to a string object variable; on return, if the method was successful, this variable contains a string object that describes the file system. You should not rely on this description for program logic but can use it in message strings. Values can include “hard,” “nfs,” and “foreign."

    fileSystemType

    On input, a pointer to a string object variable; on return, if the method was successful, this variable contains the file-system type. Values can include “HFS,” “UFS,” or other values.

    Return Value

    YEStrue if the information was successfully returned, otherwise NOfalse.

    Discussion

    It is safe to call this method from any thread of your app.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Determines whether the specified path is a file package.

    Declaration

    Swift

    func isFilePackageAtPath(_ fullPath: String) -> Bool

    Objective-C

    - (BOOL)isFilePackageAtPath:(NSString *)fullPath

    Parameters

    fullPath

    The full path to examine.

    Return Value

    YEStrue if the path identifies a file package; otherwise, NOfalse if the path does not exist, is not a directory, or is not a file package.

    Discussion

    It is safe to call this method from any thread of your app.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns the frontmost app, which is the app that receives key events.

    Declaration

    Swift

    var frontmostApplication: NSRunningApplication? { get }

    Objective-C

    @property(readonly, strong) NSRunningApplication *frontmostApplication

    Return Value

    The running app instance for the app that receives key events.

    Discussion

    This value is key-value observing compliant.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.7 and later.

  • Returns an array of NSRunningApplication representing the running apps.

    Declaration

    Swift

    var runningApplications: [AnyObject] { get }

    Objective-C

    @property(readonly, copy) NSArray *runningApplications

    Return Value

    An array of NSRunningApplication instances.

    Discussion

    The order of the array is unspecified, but it is stable, meaning that the relative order of particular apps will not change across multiple calls to runningApplications. See NSRunningApplication Class Reference for more information on NSRunningApplication.

    Similar to the NSRunningApplication class’s properties, this property will only change when the main run loop is run in a common mode. Instead of polling, use key-value observing to be notified of changes to this array property.

    It is safe to call this method from any of your app’s threads. The method returns its value atomically.

    This value returned by this method is observable using key-value observing.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • Returns the app that owns the currently displayed menu bar.

    Declaration

    Swift

    var menuBarOwningApplication: NSRunningApplication? { get }

    Objective-C

    @property(readonly, strong) NSRunningApplication *menuBarOwningApplication

    Return Value

    The running app instance for the app that owns the displayed menu bar.

    Discussion

    This value is key-value observing compliant.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.7 and later.

  • Returns an image containing the icon for the specified file.

    Declaration

    Swift

    func iconForFile(_ fullPath: String) -> NSImage

    Objective-C

    - (NSImage *)iconForFile:(NSString *)fullPath

    Parameters

    fullPath

    The full path to the file.

    Return Value

    The icon associated with the file.

    Discussion

    The returned image has an initial size of 32 pixels by 32 pixels.

    It is safe to call this method from any thread of your app.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns an image containing the icon for files of the specified type.

    Declaration

    Swift

    func iconForFileType(_ fileType: String) -> NSImage

    Objective-C

    - (NSImage *)iconForFileType:(NSString *)fileType

    Parameters

    fileType

    The file type, which may be either a filename extension, an encoded HFS file type, or a universal type identifier (UTI).

    Return Value

    The icon associated with files of the given type.

    Discussion

    The returned image has an initial size of 32 pixels by 32 pixels.

    It is safe to call this method from any thread of your app.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Returns an image containing the icon for the specified files.

    Declaration

    Swift

    func iconForFiles(_ fullPaths: [AnyObject]) -> NSImage?

    Objective-C

    - (NSImage *)iconForFiles:(NSArray *)fullPaths

    Parameters

    fullPaths

    An array of NSString objects, each of which contains the full path to a file.

    Return Value

    The icon associated with the group of files.

    Discussion

    If fullPaths specifies one file, that file's icon is returned. If fullPaths specifies more than one file, an icon representing the multiple selection is returned.

    It is safe to call this method from any thread of your app.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Sets the icon for the file or directory at the specified path.

    Declaration

    Swift

    func setIcon(_ image: NSImage, forFile fullPath: String, options options: NSWorkspaceIconCreationOptions) -> Bool

    Objective-C

    - (BOOL)setIcon:(NSImage *)image forFile:(NSString *)fullPath options:(NSWorkspaceIconCreationOptions)options

    Parameters

    image

    The image to use as the icon for the file or directory.

    fullPath

    The full path of the file or directory.

    options

    The icon representations to generate from the image. You specify this value by combining the appropriate Workspace icon creation options constants, using the C bitwise OR operator. Specify 0 if you want to generate icons in all available icon representation formats.

    Return Value

    YEStrue if the icon was set; otherwise, NOfalse.

    Discussion

    The image can be an arbitrary image, with or without transparency. This image is automatically scaled (as needed) to generate the icon representations. The file or folder must exist and be writable by the user.

    This method uses the image to set an icon whose size is 512 by 512 pixels. If you specify the NSExclude10_4ElementsIconCreationOption option (not recommended), this method creates an icon that is compatible with the pre-OS X v10.3 Finder.

    It is safe to call this method from any of your app’s threads, but you must call it from only one thread at a time.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Unmounts and ejects the device at the specified path.

    Declaration

    Swift

    func unmountAndEjectDeviceAtPath(_ path: String) -> Bool

    Objective-C

    - (BOOL)unmountAndEjectDeviceAtPath:(NSString *)path

    Parameters

    path

    The path to the device.

    Return Value

    YEStrue if the device was unmounted; otherwise, NOfalse.

    Discussion

    When this method begins, it posts an NSWorkspaceWillUnmountNotification to the NSWorkspace object’s notification center. When it is finished, it posts an NSWorkspaceDidUnmountNotification.

    The unmountAndEjectDeviceAtURL:error: is preferable because it provides more detailed error information.

    It is safe to call this method from any thread of your app.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Attempts to eject the volume mounted at the given path.

    Declaration

    Swift

    func unmountAndEjectDeviceAtURL(_ url: NSURL, error error: NSErrorPointer) -> Bool

    Objective-C

    - (BOOL)unmountAndEjectDeviceAtURL:(NSURL *)url error:(NSError **)error

    Parameters

    url

    The URL of the volume to eject.

    error

    If the operation fails, this error contains more information about the failure.

    Return Value

    YEStrue if the volume was unmounted and ejected successfully, otherwise NOfalse, for example, if the volume is not ejectable.

    Discussion

    It is safe to call this method from any thread of your app.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • Displays a Spotlight search results window in Finder for the specified query string.

    Declaration

    Swift

    func showSearchResultsForQueryString(_ queryString: String) -> Bool

    Objective-C

    - (BOOL)showSearchResultsForQueryString:(NSString *)queryString

    Parameters

    queryString

    The string to search for.

    Return Value

    YEStrue if the communication with Finder was successful, otherwise NOfalse.

    Discussion

    Finder becomes the active app, if possible. The user can further refine the search via the Finder user interface.

    It is safe to call this method from any thread of your app.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • Returns the corresponding array of file label colors for the file labels.

    Declaration

    Swift

    var fileLabelColors: [AnyObject] { get }

    Objective-C

    @property(readonly, copy) NSArray *fileLabelColors

    Return Value

    An array of NSColor objects.

    Discussion

    This array has the same number of elements as fileLabels, and the color at a given index corresponds to the label at the same index.

    You can listen for notifications named NSWorkspaceDidChangeFileLabelsNotification to be notified when file labels change which may result in changes to the order of the fileLabelColors.

    It is safe to call this method from any thread of your app.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.6 and later.

    See Also

    – fileLabels

  • Returns the array of file labels as strings.

    Declaration

    Swift

    var fileLabels: [AnyObject] { get }

    Objective-C

    @property(readonly, copy) NSArray *fileLabels

    Return Value

    An array of strings.

    Discussion

    You can listen for notifications named NSWorkspaceDidChangeFileLabelsNotification to be notified when file labels change.

    It is safe to call this method from any thread of your app.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • Informs the workspace object that the file system changed at the specified path.

    Declaration

    Swift

    func noteFileSystemChanged(_ path: String)

    Objective-C

    - (void)noteFileSystemChanged:(NSString *)path

    Parameters

    path

    The full path that changed.

    Discussion

    Use of this method is discouraged. If you want to track changes to files and directories, use the FSEvents API described in FSEvents Reference.

    The NSWorkspace object uses this method to track changes to all the files and directories it is interested in.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Requests the system wait for the specified amount of time before turning off the power or logging out the user.

    Declaration

    Swift

    func extendPowerOffBy(_ requested: Int) -> Int

    Objective-C

    - (NSInteger)extendPowerOffBy:(NSInteger)requested

    Parameters

    requested

    The number of milliseconds to wait before turning off the power or logging off the user.

    Return Value

    The number of milliseconds granted by the system.

    Discussion

    Currently unimplemented. Do not call it.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Opens the specified temporary file using the default app for its type.

    Deprecation Statement

    Use the openFile: method instead.

    Declaration

    Objective-C

    - (BOOL)openTempFile:(NSString *)fullPath

    Parameters

    fullPath

    The full path to the temporary file.

    Return Value

    YEStrue if the file was successfully opened; otherwise, NOfalse.

    Discussion

    The sending app is deactivated before the request is sent. Using this method instead of one of the openFile:... methods lets the receiving app know that it should delete the file when it no longer needs it. Currently provides the same functionality as openFile:.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.6.

  • Examines all apps and updates the records of registered services and file types.

    Deprecation Statement

    Do not use.

    Declaration

    Objective-C

    - (void)findApplications

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.6.

  • Informs the NSWorkspace object that the defaults database has changed.

    Deprecation Statement

    Register for the NSUserDefaultsDidChangeNotification notification instead.

    Declaration

    Objective-C

    - (void)noteUserDefaultsChanged

    Discussion

    The NSWorkspace object then reads all the defaults it is interested in and reconfigures itself appropriately. For example, this method is used by the Preferences app to notify the Finder whether the user prefers to see hidden files. Currently has no effect.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.6.

  • Animates a sliding image from one point to another.

    Deprecation Statement

    Do not use.

    Declaration

    Objective-C

    - (void)slideImage:(NSImage *)image from:(NSPoint)fromPoint to:(NSPoint)toPoint

    Parameters

    image

    The image to animate.

    fromPoint

    The starting point, in screen coordinates.

    toPoint

    The ending point, in screen coordinates.

    Discussion

    Currently unimplemented.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.6.

  • Polls the system’s drives for any disks that have been inserted but not yet mounted.

    Deprecation Statement

    Do not use.

    Declaration

    Objective-C

    - (void)checkForRemovableMedia

    Discussion

    This method doesn’t wait until such disks are mounted; instead, it requests that the disk be mounted asynchronously and returns immediately. Currently has no effect.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.6.

  • Informs the NSWorkspace object that the file system has changed.

    Deprecation Statement

    Use the FSEvents API described in FSEvents Reference instead.

    Declaration

    Objective-C

    - (void)noteFileSystemChanged

    Discussion

    The NSWorkspace object then gets the status of all the files and directories it is interested in and updates itself appropriately. This method is used by many objects that write or delete files.

    The NSDocument and NSSavePanel objects use this method when saving a file. If you create a file directly, you should call noteFileSystemChanged so that the Finder can update the folder if it is open.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.6.

  • Returns a Boolean value indicating whether a change to the file system has been registered with a noteFileSystemChanged message since the last fileSystemChanged message.

    Deprecation Statement

    Use the FSEvents API described in FSEvents Reference instead.

    Declaration

    Objective-C

    - (BOOL)fileSystemChanged

    Return Value

    Currently, this method always returns NOfalse.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.6.

  • Returns a Boolean value indicating whether a change to the defaults database has been registered with a noteUserDefaultsChanged message since the last userDefaultsChanged message.

    Deprecation Statement

    Register for the NSUserDefaultsDidChangeNotification notification instead.

    Declaration

    Objective-C

    - (BOOL)userDefaultsChanged

    Return Value

    Currently, this method always returns NOfalse.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.6.

  • Returns the full pathnames of any newly mounted disks.

    Deprecation Statement

    Do not use.

    Declaration

    Objective-C

    - (NSArray *)mountNewRemovableMedia

    Return Value

    An array of NSString objects, each of which contains the full pathname to a newly mounted disk.

    Discussion

    This method polls the system’s drives for any disks that have been inserted but not yet mounted and waits until the new disks have been mounted. This method posts an NSWorkspaceDidMountNotification to the NSWorkspace object’s notification center when it is finished. Currently provides the same functionality as mountedRemovableMedia.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.6.

  • Returns the full pathnames of all currently mounted removable disks.

    Deprecation Statement

    Do not use.

    Declaration

    Swift

    func mountedRemovableMedia() -> [AnyObject]!

    Objective-C

    - (NSArray *)mountedRemovableMedia

    Return Value

    An array of NSString objects, each of which contains the full pathname of a mounted removable disk.

    Discussion

    If the computer provides an interrupt or other notification when the user inserts a disk into a drive, the Finder will mount the disk immediately. However, if no notification is given, the Finder won’t be aware that a disk needs to be mounted. On such systems, an app should invoke either mountNewRemovableMedia or checkForRemovableMedia before invoking mountedRemovableMedia. Either of these methods cause the Finder to poll the drives to see if a disk is present. If a disk has been inserted but not yet mounted, these methods will cause the Finder to mount it.

    The Disk button in an Open or Save panel invokes mountedRemovableMedia and mountNewRemovableMedia as part of its operation, so most apps won’t need to invoke these methods directly.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.7.

  • Returns the mount points of all local volumes, not just the removable ones returned by mountedRemovableMedia.

    Deprecation Statement

    Do not use.

    Declaration

    Swift

    func mountedLocalVolumePaths() -> [AnyObject]?

    Objective-C

    - (NSArray *)mountedLocalVolumePaths

    Return Value

    An array of NSString objects, each of which contains the full pathname of the mount point for any local volumes.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.7.

  • Returns a dictionary with information about the current active app.

    Deprecation Statement

    Use the frontmostApplication or menuBarOwningApplication method instead.

    Declaration

    Swift

    func activeApplication() -> [NSObject : AnyObject]?

    Objective-C

    - (NSDictionary *)activeApplication

    Return Value

    A dictionary with information about the app. The dictionary contains as many of the keys described in Table 1 as are available.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.2 and later.

    Deprecated in OS X v10.7.

  • Returns an array of dictionaries, one entry for each running app.

    Deprecation Statement

    Use the runningApplications method instead.

    Declaration

    Objective-C

    - (NSArray *)launchedApplications

    Return Value

    An array of NSDictionary objects. Each dictionary contains as many of the keys described in Table 1 as are available.

    Import Statement

    Objective-C

    @import AppKit;

    Availability

    Available in OS X v10.0 and later.

    Deprecated in OS X v10.7.

  • These constants specify different types of files returned by the getInfoForFile:application:type: method.

    Declaration

    Objective-C

    NSString *NSPlainFileType; NSString *NSDirectoryFileType; NSString *NSApplicationFileType; NSString *NSFilesystemFileType; NSString *NSShellCommandFileType;

    Constants

    • NSPlainFileType

      NSPlainFileType

      Plain (untyped) file

      Available in OS X v10.0 and later.

      Deprecated in OS X v10.6.

    • NSDirectoryFileType

      NSDirectoryFileType

      Directory

      Available in OS X v10.0 and later.

      Deprecated in OS X v10.6.

    • NSApplicationFileType

      NSApplicationFileType

      Cocoa app

      Available in OS X v10.0 and later.

      Deprecated in OS X v10.6.

    • NSFilesystemFileType

      NSFilesystemFileType

      File-system mount point

      Available in OS X v10.0 and later.

      Deprecated in OS X v10.6.

    • NSShellCommandFileType

      NSShellCommandFileType

      Executable shell command

      Available in OS X v10.0 and later.

      Deprecated in OS X v10.6.

  • The following keys can be used in the configuration dictionary of the launchApplicationAtURL:options:configuration:error: method. Each key is optional, and if omitted, default behavior is applied.

    Declaration

    Swift

    let NSWorkspaceLaunchConfigurationAppleEvent: NSString! let NSWorkspaceLaunchConfigurationArguments: NSString! let NSWorkspaceLaunchConfigurationEnvironment: NSString! let NSWorkspaceLaunchConfigurationArchitecture: NSString!

    Objective-C

    NSString * const NSWorkspaceLaunchConfigurationAppleEvent; NSString * const NSWorkspaceLaunchConfigurationArguments; NSString * const NSWorkspaceLaunchConfigurationEnvironment; NSString * const NSWorkspaceLaunchConfigurationArchitecture;

    Constants

    • NSWorkspaceLaunchConfigurationAppleEvent

      NSWorkspaceLaunchConfigurationAppleEvent

      The value is the first NSAppleEventDescriptor to send to the new app. If an instance of the app is already running, this is sent to that app.

      Available in OS X v10.6 and later.

    • NSWorkspaceLaunchConfigurationArguments

      NSWorkspaceLaunchConfigurationArguments

      The value is an NSArray of NSStrings, passed to the new app in the argv parameter. Ignored if a new instance of the app is not launched.

      Available in OS X v10.6 and later.

    • NSWorkspaceLaunchConfigurationEnvironment

      NSWorkspaceLaunchConfigurationEnvironment

      The value is an NSDictionary, mapping NSStrings to NSStrings, containing environment variables to set for the new app. Ignored if a new instance of the app is not launched.

      Available in OS X v10.6 and later.

    • NSWorkspaceLaunchConfigurationArchitecture

      NSWorkspaceLaunchConfigurationArchitecture

      The value is an NSNumber containing an Mach-O Architecture constant. Ignored if a new instance of the app is not launched.

      Available in OS X v10.6 and later.

  • These constants specify different types of file operations used by performFileOperation:source:destination:files:tag:.

    Declaration

    Swift

    var NSWorkspaceMoveOperation: NSString! var NSWorkspaceCopyOperation: NSString! var NSWorkspaceLinkOperation: NSString! var NSWorkspaceCompressOperation: NSString! var NSWorkspaceDecompressOperation: NSString! var NSWorkspaceEncryptOperation: NSString! var NSWorkspaceDecryptOperation: NSString! var NSWorkspaceDestroyOperation: NSString! var NSWorkspaceRecycleOperation: NSString! var NSWorkspaceDuplicateOperation: NSString!

    Objective-C

    NSString *NSWorkspaceMoveOperation; NSString *NSWorkspaceCopyOperation; NSString *NSWorkspaceLinkOperation; NSString *NSWorkspaceCompressOperation; NSString *NSWorkspaceDecompressOperation; NSString *NSWorkspaceEncryptOperation; NSString *NSWorkspaceDecryptOperation; NSString *NSWorkspaceDestroyOperation; NSString *NSWorkspaceRecycleOperation; NSString *NSWorkspaceDuplicateOperation;

    Constants

    • NSWorkspaceMoveOperation

      NSWorkspaceMoveOperation

      Move file to destination. Behaves the same as movePath:toPath:handler:.

      Available in OS X v10.0 and later.

    • NSWorkspaceCopyOperation

      NSWorkspaceCopyOperation

      Copy file to destination. Behaves the same as copyPath:toPath:handler:.

      Available in OS X v10.0 and later.

    • NSWorkspaceLinkOperation

      NSWorkspaceLinkOperation

      Create hard link to file in destination. Behaves the same as linkPath:toPath:handler:.

      Available in OS X v10.0 and later.

    • NSWorkspaceCompressOperation

      NSWorkspaceCompressOperation

      Compress file. This operation always returns an error.

      Available in OS X v10.0 and later.

    • NSWorkspaceDecompressOperation

      NSWorkspaceDecompressOperation

      Decompress file. This operation always returns an error.

      Available in OS X v10.0 and later.

    • NSWorkspaceEncryptOperation

      NSWorkspaceEncryptOperation

      Encrypt file. This operation always returns an error.

      Available in OS X v10.0 and later.

    • NSWorkspaceDecryptOperation

      NSWorkspaceDecryptOperation

      Decrypt file. This operation always returns an error.

      Available in OS X v10.0 and later.

    • NSWorkspaceDestroyOperation

      NSWorkspaceDestroyOperation

      Destroy file. Behaves the same as removeFileAtPath:handler:.

      Available in OS X v10.0 and later.

    • NSWorkspaceRecycleOperation

      NSWorkspaceRecycleOperation

      Move file to trash. The file is moved to the trash folder on the volume containing the file using the same semantics as NSWorkspaceMoveOperation. If a file with the same name currently exists in the trash folder, the new file is renamed. If no trash folder exists on the volume containing the file, the operation fails.

      Available in OS X v10.0 and later.

    • NSWorkspaceDuplicateOperation

      NSWorkspaceDuplicateOperation

      Duplicate file in source directory.

      Available in OS X v10.0 and later.

  • The following keys may be specified or returned in the options dictionary for setDesktopImageURL:forScreen:options:error:.

    Declaration

    Swift

    let NSWorkspaceDesktopImageScalingKey: NSString! let NSWorkspaceDesktopImageAllowClippingKey: NSString! let NSWorkspaceDesktopImageFillColorKey: NSString!

    Objective-C

    NSString * const NSWorkspaceDesktopImageScalingKey; NSString * const NSWorkspaceDesktopImageAllowClippingKey; NSString * const NSWorkspaceDesktopImageFillColorKey;

    Constants

    • NSWorkspaceDesktopImageScalingKey

      NSWorkspaceDesktopImageScalingKey

      The value is an NSNumber containing an NSImageScaling constant as declared in NSCell. If this is not specified, NSImageScaleProportionallyUpOrDown is used. NSImageScaleProportionallyDown is not currently supported.

      Available in OS X v10.6 and later.

    • NSWorkspaceDesktopImageAllowClippingKey

      NSWorkspaceDesktopImageAllowClippingKey

      The value is an NSNumber containing a BOOL, which affects the interpretation of Proportional scaling types. A NOfalse value will make the image fully visible, but there may be empty space on the sides or top and bottom. A YEStrue value will cause the image to fill the entire screen, but the image may be clipped. If this is not specified, NOfalse is assumed. Non-proportional scaling types ignore this value.

      Available in OS X v10.6 and later.

    • NSWorkspaceDesktopImageFillColorKey

      NSWorkspaceDesktopImageFillColorKey

      The value is an NSColor, which is used to fill any empty space around the image. If not specified, a default value is used. Currently, only colors that use or can be converted to use NSCalibratedRGBColorSpace are supported, and any alpha value is ignored.

      Available in OS X v10.6 and later.

  • Declaration

    Swift

    struct NSWorkspaceLaunchOptions : RawOptionSetType { init(_ rawValue: UInt) init(rawValue rawValue: UInt) static var AndPrint: NSWorkspaceLaunchOptions { get } static var WithErrorPresentation: NSWorkspaceLaunchOptions { get } static var InhibitingBackgroundOnly: NSWorkspaceLaunchOptions { get } static var WithoutAddingToRecents: NSWorkspaceLaunchOptions { get } static var WithoutActivation: NSWorkspaceLaunchOptions { get } static var Async: NSWorkspaceLaunchOptions { get } static var AllowingClassicStartup: NSWorkspaceLaunchOptions { get } static var PreferringClassic: NSWorkspaceLaunchOptions { get } static var NewInstance: NSWorkspaceLaunchOptions { get } static var AndHide: NSWorkspaceLaunchOptions { get } static var AndHideOthers: NSWorkspaceLaunchOptions { get } static var Default: NSWorkspaceLaunchOptions { get } }

    Objective-C

    enum { NSWorkspaceLaunchAndPrint = 0x00000002, NSWorkspaceLaunchWithErrorPresentation = 0x00000040, NSWorkspaceLaunchInhibitingBackgroundOnly = 0x00000080, NSWorkspaceLaunchWithoutAddingToRecents = 0x00000100, NSWorkspaceLaunchWithoutActivation = 0x00000200, NSWorkspaceLaunchAsync = 0x00010000, NSWorkspaceLaunchAllowingClassicStartup = 0x00020000, NSWorkspaceLaunchPreferringClassic = 0x00040000, NSWorkspaceLaunchNewInstance = 0x00080000, NSWorkspaceLaunchAndHide = 0x00100000, NSWorkspaceLaunchAndHideOthers = 0x00200000, NSWorkspaceLaunchDefault = NSWorkspaceLaunchAsync | NSWorkspaceLaunchAllowingClassicStartup }; typedef NSUInteger NSWorkspaceLaunchOptions;

    Constants

    • AndPrint

      NSWorkspaceLaunchAndPrint

      Print items instead of opening them.

      Available in OS X v10.3 and later.

    • WithErrorPresentation

      NSWorkspaceLaunchWithErrorPresentation

      Display an error panel to the user if a failure occurs.

      Available in OS X v10.9 and later.

    • InhibitingBackgroundOnly

      NSWorkspaceLaunchInhibitingBackgroundOnly

      Causes launch to fail if the target is background-only.

      Available in OS X v10.3 and later.

    • WithoutAddingToRecents

      NSWorkspaceLaunchWithoutAddingToRecents

      Do not add the app or documents to the Recents menu.

      Available in OS X v10.3 and later.

    • WithoutActivation

      NSWorkspaceLaunchWithoutActivation

      Launch the app but do not bring it into the foreground.

      Available in OS X v10.3 and later.

    • Async

      NSWorkspaceLaunchAsync

      Launch the app and return the results asynchronously.

      Available in OS X v10.3 and later.

    • AllowingClassicStartup

      NSWorkspaceLaunchAllowingClassicStartup

      Start up the Classic compatibility environment, if it is required by the app.

      Available in OS X v10.3 and later.

    • PreferringClassic

      NSWorkspaceLaunchPreferringClassic

      Force the app to launch in the Classic compatibility environment.

      Available in OS X v10.3 and later.

    • NewInstance

      NSWorkspaceLaunchNewInstance

      Create a new instance of the app, even if one is already running.

      Available in OS X v10.3 and later.

    • AndHide

      NSWorkspaceLaunchAndHide

      Tell the app to hide itself as soon as it has finished launching.

      Available in OS X v10.3 and later.

    • AndHideOthers

      NSWorkspaceLaunchAndHideOthers

      Hide all apps except the newly launched one.

      Available in OS X v10.3 and later.

    • Default

      NSWorkspaceLaunchDefault

      Launch the app asynchronously and launch it in the Classic environment, if required.

      Available in OS X v10.3 and later.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • The following keys are available in the userInfo parameter of the notification named NSWorkspaceDidRenameVolumeNotification.

    Declaration

    Swift

    let NSWorkspaceVolumeLocalizedNameKey: NSString! let NSWorkspaceVolumeURLKey: NSString!

    Objective-C

    NSString * const NSWorkspaceVolumeLocalizedNameKey; NSString * const NSWorkspaceVolumeURLKey;

    Constants

    • NSWorkspaceVolumeLocalizedNameKey

      NSWorkspaceVolumeLocalizedNameKey

      NSString containing the user-visible name of the volume.

      Available in OS X v10.6 and later.

    • NSWorkspaceVolumeURLKey

      NSWorkspaceVolumeURLKey

      NSURL containing the mount path of the volume.

      Available in OS X v10.6 and later.

  • The following keys are available in the userInfo parameter of the notification named NSWorkspaceDidRenameVolumeNotification.

    Declaration

    Swift

    let NSWorkspaceVolumeOldLocalizedNameKey: NSString! let NSWorkspaceVolumeOldURLKey: NSString!

    Objective-C

    NSString * const NSWorkspaceVolumeOldLocalizedNameKey; NSString * const NSWorkspaceVolumeOldURLKey;

    Constants

    • NSWorkspaceVolumeOldLocalizedNameKey

      NSWorkspaceVolumeOldLocalizedNameKey

      NSString containing the old user-visible name of the volume

      Available in OS X v10.6 and later.

    • NSWorkspaceVolumeOldURLKey

      NSWorkspaceVolumeOldURLKey

      NSURL containing the old mount path of the volume

      Available in OS X v10.6 and later.

  • This constant is supplied in the userInfo dictionary of various notifications.

    Declaration

    Swift

    let NSWorkspaceApplicationKey: NSString!

    Objective-C

    NSString * const NSWorkspaceApplicationKey;

    Constants

    • NSWorkspaceApplicationKey

      NSWorkspaceApplicationKey

      The value corresponding to this key is an instance of NSRunningApplication that reflects the affected app.

      Available in OS X v10.6 and later.

  • These constants describe the NSWorkspaceIconCreationOptions values used by setIcon:forFile:options:. You can combine these using the C bitwise OR operator.

    Declaration

    Swift

    struct NSWorkspaceIconCreationOptions : RawOptionSetType { init(_ rawValue: UInt) init(rawValue rawValue: UInt) static var ExcludeQuickDrawElementsIconCreationOption: NSWorkspaceIconCreationOptions { get } static var Exclude10_4ElementsIconCreationOption: NSWorkspaceIconCreationOptions { get } }

    Objective-C

    enum { NSExcludeQuickDrawElementsIconCreationOption = 1 << 1, NSExclude10_4ElementsIconCreationOption = 1 << 2 }; typedef NSUInteger NSWorkspaceIconCreationOptions;

    Constants

    • ExcludeQuickDrawElementsIconCreationOption

      NSExcludeQuickDrawElementsIconCreationOption

      Suppress generation of the QuickDraw format icon representations that are used in OS X v10.0 through OS X v10.4.

      Available in OS X v10.4 and later.

    • Exclude10_4ElementsIconCreationOption

      NSExclude10_4ElementsIconCreationOption

      Suppress generation of the new higher resolution icon representations that are supported in OS X v10.4.

      Available in OS X v10.4 and later.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.4 and later.

  • Posted when the Finder is about to launch an app.

    The notification object is the shared NSWorkspace instance. In OS X v10.6 and later the userInfo dictionary contains the NSWorkspaceApplicationKey key with a corresponding instance of NSRunningApplication that represents the affected app.

    In OS X v10.5 and earlier the userInfo dictionary contains the keys and values described in Table 1.

    The system does not post this notification for background apps or for apps that have the LSUIElement key in their Info.plist file. If you want to know when all apps (including background apps) are launched or terminated, use key-value observing to monitor the value returned by the runningApplications method.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Posted when a new app has started up.

    The notification object is the shared NSWorkspace instance. In OS X v10.6 and later the userInfo dictionary contains the NSWorkspaceApplicationKey key with a corresponding instance of NSRunningApplication that represents the affected app.

    In OS X v10.5 and earlier the userInfo dictionary contains the keys and values described in Table 1.

    The system does not post this notification for background apps or for apps that have the LSUIElement key in their Info.plist file. If you want to know when all apps (including background apps) are launched or terminated, use key-value observing to monitor the value returned by the runningApplications method.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Posted when an app finishes executing.

    The notification object is the shared NSWorkspace instance. In OS X v10.6 and later the userInfo dictionary contains the NSWorkspaceApplicationKey key with a corresponding instance of NSRunningApplication that represents the affected app.

    In OS X v10.5 and earlier the userInfo dictionary contains the keys and values described in Table 1.

    The system does not post this notification for background apps or for apps that have the LSUIElement key in their Info.plist file. If you want to know when all apps (including background apps) are launched or terminated, use key-value observing to monitor the value returned by the runningApplications method.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Posted after a user session is switched in. This allows an app to re-enable some processing when a switched out session gets switched back in, for example.

    The notification object is the shared NSWorkspace instance. The notification does not contain a userInfo dictionary.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Posted before a user session is switched out. This allows an app to disable some processing when its user session is switched out, and re-enable when that session gets switched back in, for example.

    The notification object is the shared NSWorkspace instance. The notification does not contain a userInfo dictionary.

    If an app is launched in an inactive session, NSWorkspaceSessionDidResignActiveNotification is sent after NSApplicationWillFinishLaunchingNotification and before sending NSApplicationDidFinishLaunchingNotification.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Posted when the Finder hid an app.

    The notification object is the shared NSWorkspace instance. In OS X v10.6 and later the userInfo dictionary contains the NSWorkspaceApplicationKey key with a corresponding instance of NSRunningApplication that represents the affected app.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • Posted when the Finder unhid an app.

    The notification object is the shared NSWorkspace instance. In OS X v10.6 and later the userInfo dictionary contains the NSWorkspaceApplicationKey key with a corresponding instance of NSRunningApplication that represents the affected app.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • Posted when the Finder is about to activate an app.

    The notification object is the shared NSWorkspace instance. In OS X v10.6 and later the userInfo dictionary contains the NSWorkspaceApplicationKey key with a corresponding instance of NSRunningApplication that represents the affected app.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • Posted when the Finder deactivated an app.

    The notification object is the shared NSWorkspace instance. In OS X v10.6 and later the userInfo dictionary contains the NSWorkspaceApplicationKey key with a corresponding instance of NSRunningApplication that represents the affected app.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • Posted when a volume changes its name and/or mount path. These typically change simultaneously, in which case only one notification is posted.

    The notification object is the shared NSWorkspace instance. The userInfo dictionary contains keys in NSWorkspaceDidRenameVolumeNotification User Info Keys and Volume Mounting Notification User Info Keys.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • Posted when a new device has been mounted.

    The notification object is the shared NSWorkspace instance.

    In OS X v10.5 and earlier the userInfo dictionary contains a key @"NSDevicePath" that returns the path where the device was mounted, as a string.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Posted when the Finder is about to unmount a device.

    This notification will not be delivered if a volume was forcibly and immediately made unavailable, such as when a FireWire drive is simply unplugged, because there is no chance to deliver it before the volume becomes unavailable.

    The notification object is the shared NSWorkspace instance. The userInfo dictionary contains a key @"NSDevicePath" that returns the path where the device was mounted, as a string.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Posted when the Finder did unmount a device.

    This notification is delivered even if a volume was forcibly and immediately made unavailable, such as when a drive is simply unplugged.

    The notification object is the shared NSWorkspace instance. The userInfo dictionary contains a key @"NSDevicePath" that returns the path where the device was mounted, as a string.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Posted when a file operation has been performed in the receiving app.

    The notification object is the shared NSWorkspace instance. The userInfo dictionary contains a key @"NSOperationNumber" with a NSNumber object containing an integer indicating the type of file operation

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Posted when the Finder file labels or colors change.

    The notification object is the shared NSWorkspace instance. The notification does not contain a userInfo dictionary.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • Posted when a Spaces change has occurred.

    The notification object is the shared NSWorkspace instance. The notification does not contain a userInfo dictionary.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • Posted when the machine wakes from sleep.

    The notification object is the shared NSWorkspace instance. The notification does not contain a userInfo dictionary.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Posted when the user has requested a logout or that the machine be powered off.

    The notification object is the shared NSWorkspace instance. This notification does not contain a userInfo dictionary.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.0 and later.

  • Posted before the machine goes to sleep. An observer of this message can delay sleep for up to 30 seconds while handling this notification.

    The notification object is the shared NSWorkspace instance. The notification does not contain a userInfo dictionary.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.3 and later.

  • Posted when the machine’s screen goes to sleep.

    The notification object is the shared NSWorkspace instance. The notification does not contain a userInfo dictionary.

    Few apps are likely to be interested in this notification, but they may be useful for certain hardware-based drawing decisions, for example when using OpenGL.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.6 and later.

  • Posted when the machine’s screens wake.

    The notification object is the shared NSWorkspace instance. The notification does not contain a userInfo dictionary.

    Few apps are likely to be interested in this notification, but they may be useful for certain hardware-based drawing decisions, for example when using OpenGL.

    Import Statement

    Objective-C

    @import AppKit;

    Swift

    import AppKit

    Availability

    Available in OS X v10.6 and later.