NSWorkspace Class Reference

Inherits from
Conforms to
Framework
/System/Library/Frameworks/AppKit.framework
Availability
Available in OS X v10.0 and later.
Companion guide
Declared in
NSRunningApplication.h
NSWorkspace.h
Related sample code

Overview

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

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"];

Tasks

Accessing the Shared NSWorkspace Instance

Accessing the NSWorkspace Notification Center

Opening Files

Manipulating Applications

Manipulating Files

Manipulating Uniform Type Identifier Information

Requesting Information

Managing Icons

Unmounting a Device

Working with Bundles

Managing the Desktop Image

Performing Finder Spotlight Searches

Finder File Labels

Tracking Changes to the File System

Requesting Additional Time Before Logout

Deprecated Methods

Class Methods

sharedWorkspace

Returns the shared NSWorkspace instance.

+ (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.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSWorkspace.h

Instance Methods

absolutePathForAppBundleWithIdentifier:

Returns the absolute file-system path of an app bundle.

- (NSString *)absolutePathForAppBundleWithIdentifier:(NSString *)bundleIdentifier
Parameters
bundleIdentifier

The bundle identifier string. This value corresponds to the value in the CFBundleIdentifier key of the app’s Info.plist file. For example, the bundle identifier of the TextEdit app is com.apple.TextEdit.

Return Value

The file system path to the app bundle identified by bundleIdentifier, or nil if the bundle cannot be found.

Discussion

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

Availability
  • Available in OS X v10.3 and later.
Declared In
NSWorkspace.h

activateFileViewerSelectingURLs:

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

- (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.

Availability
  • Available in OS X v10.6 and later.
Related Sample Code
Declared In
NSWorkspace.h

desktopImageOptionsForScreen:

Returns the desktop image options for the given screen.

- (NSDictionary *)desktopImageOptionsForScreen:(NSScreen *)screen
Parameters
screen

The screen for which to get the desktop image options.

Return Value

A dictionary containing key-value pairs specified in “Desktop Image Dictionary Keys.”

Discussion

You must call this method from your app’s main thread.

Availability
  • Available in OS X v10.6 and later.
Related Sample Code
Declared In
NSWorkspace.h

desktopImageURLForScreen:

Returns the URL for the desktop image for the given screen.

- (NSURL *)desktopImageURLForScreen:(NSScreen *)screen
Parameters
screen

The screen for which to get the desktop image.

Return Value

The desktop image.

Discussion

You must call this method from your app’s main thread.

Availability
  • Available in OS X v10.6 and later.
Declared In
NSWorkspace.h

duplicateURLs:completionHandler:

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

- (void)duplicateURLs:(NSArray *)URLs completionHandler:(void (^)(NSDictionary *newURLs, NSError *error))handler
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.

Availability
  • Available in OS X v10.6 and later.
Declared In
NSWorkspace.h

extendPowerOffBy:

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

- (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.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSWorkspace.h

fileLabelColors

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

- (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.

Availability
  • Available in OS X v10.6 and later.
Declared In
NSWorkspace.h

fileLabels

Returns the array of file labels as strings.

- (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.

Availability
  • Available in OS X v10.6 and later.
Declared In
NSWorkspace.h

filenameExtension:isValidForType:

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

- (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

YES if fileNameExtension is a valid extension for typeName, NO otherwise

Discussion

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

Availability
  • Available in OS X v10.5 and later.
Declared In
NSWorkspace.h

frontmostApplication

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

- (NSRunningApplication *)frontmostApplication
Return Value

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

Discussion

This value is key-value observing compliant.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSWorkspace.h

fullPathForApplication:

Returns the full path for the specified app.

- (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.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSWorkspace.h

getFileSystemInfoForPath:isRemovable:isWritable:isUnmountable:description:type:

Describes the file system at fullPath.

- (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 YES if the file system is on removable media.

writableFlag

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

unmountableFlag

On input, a boolean variable; on return, this variable contains YES 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

YES if the information was successfully returned, otherwise NO.

Discussion

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

Availability
  • Available in OS X v10.0 and later.
Declared In
NSWorkspace.h

getInfoForFile:application:type:

Retrieves information about the specified file.

- (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

YES if the information was retrieved successfully; otherwise, NO 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.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSWorkspace.h

hideOtherApplications

Hides all applications other than the sender.

- (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.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSWorkspace.h

iconForFile:

Returns an image containing the icon for the specified file.

- (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.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSWorkspace.h

iconForFiles:

Returns an image containing the icon for the specified files.

- (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.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSWorkspace.h

iconForFileType:

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

- (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.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSWorkspace.h

isFilePackageAtPath:

Determines whether the specified path is a file package.

- (BOOL)isFilePackageAtPath:(NSString *)fullPath
Parameters
fullPath

The full path to examine.

Return Value

YES if the path identifies a file package; otherwise, NO 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.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSWorkspace.h

launchApplication:

Launches the specified app.

- (BOOL)launchApplication:(NSString *)appName
Parameters
appName

The name of the app to open.

Return Value

YES if the app was successfully launched or was already running; otherwise, NO.

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.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSWorkspace.h

launchApplication:showIcon:autolaunch:

Launches the specified app using additional options.

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

The name of the app to open.

showIcon

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

autolaunch

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

Return Value

YES if the app was successfully launched or was already running; otherwise, NO.

Discussion

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

Returns YES if the app is successfully launched or already running, and NO 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.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSWorkspace.h

launchApplicationAtURL:options:configuration:error:

Launches the app at the specified URL.

- (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.

Availability
  • Available in OS X v10.6 and later.
Declared In
NSWorkspace.h

launchAppWithBundleIdentifier:options:additionalEventParamDescriptor:launchIdentifier:

Launches the app corresponding to the specified bundleIdentifier.

- (BOOL)launchAppWithBundleIdentifier:(NSString *)bundleIdentifier options:(NSWorkspaceLaunchOptions)options additionalEventParamDescriptor:(NSAppleEventDescriptor *)descriptor launchIdentifier:(NSNumber **)identifier
Parameters
bundleIdentifier

A bundle identifier string. This value corresponds to the value in the CFBundleIdentifier key of the app’s Info.plist file. For example, the bundle identifier of the TextEdit app is com.apple.TextEdit.

options

Options to use when launching the app. Values for this parameter are described in “NSWorkspaceLaunchOptions.”

descriptor

Additional options specified in an AppleEvent-style descriptor. For example, you could use this parameter to specify additional documents to open when the app is launched.

identifier

The launchIdentifiers are currently unused, and you should pass NULL.

Return Value

YES if the app was found and launched; otherwise, NO.

Discussion

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

Availability
  • Available in OS X v10.3 and later.
Declared In
NSWorkspace.h

localizedDescriptionForType:

Returns the localized description for the specified Uniform Type Identifier

- (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.

Availability
  • Available in OS X v10.5 and later.
Related Sample Code
Declared In
NSWorkspace.h

menuBarOwningApplication

Returns the app that owns the currently displayed menu bar.

- (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.

Availability
  • Available in OS X v10.7 and later.
Declared In
NSWorkspace.h

noteFileSystemChanged:

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

- (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.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSWorkspace.h

notificationCenter

Returns the notification center for workspace notifications.

- (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.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSWorkspace.h

openFile:

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

- (BOOL)openFile:(NSString *)fullPath
Parameters
fullPath

The full path to the file.

Return Value

YES if the file was successfully opened; otherwise, NO.

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.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSWorkspace.h

openFile:fromImage:at:inView:

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

- (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

YES if the file was successfully opened; otherwise, NO.

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.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSWorkspace.h

openFile:withApplication:

Opens a file using the specified app.

- (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

YES if the file was successfully opened; otherwise, NO.

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.

Availability
  • Available in OS X v10.0 and later.
Related Sample Code
Declared In
NSWorkspace.h

openFile:withApplication:andDeactivate:

Opens the specified file and optionally deactivates the sending app.

- (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

YES if the file was successfully opened; otherwise, NO.

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.

Availability
  • Available in OS X v10.0 and later.
Related Sample Code
Declared In
NSWorkspace.h

openURL:

Opens the location at the specified URL.

- (BOOL)openURL:(NSURL *)url
Parameters
url

A URL specifying the location to open.

Return Value

YES if the location was successfully opened; otherwise, NO.

Discussion

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

Availability
  • Available in OS X v10.0 and later.
Declared In
NSWorkspace.h

openURLs:withAppBundleIdentifier:options:additionalEventParamDescriptor:launchIdentifiers:

Opens one or more files from an array of URLs.

- (BOOL)openURLs:(NSArray *)urls withAppBundleIdentifier:(NSString *)bundleIdentifier options:(NSWorkspaceLaunchOptions)options additionalEventParamDescriptor:(NSAppleEventDescriptor *)descriptor launchIdentifiers:(NSArray **)identifiers
Parameters
urls

An array of NSURL objects, each one identifying a URL for the app to open.

bundleIdentifier

A bundle identifier string or nil to use the default system bindings. This value corresponds to the value in the CFBundleIdentifier key of the app’s Info.plist file. For example, the bundle identifier of the TextEdit app is com.apple.TextEdit.

options

Options to use when launching the app. Values for this parameter are described in “NSWorkspaceLaunchOptions.”

descriptor

Additional options specified in an AppleEvent-style descriptor. For example, you could use this parameter to specify additional documents to open when the app is launched.

identifiers

The launchIdentifiers are currently unused, and you should pass NULL.

Return Value

YES if the app was found and launched; otherwise, NO.

Discussion

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

Availability
  • Available in OS X v10.3 and later.
Declared In
NSWorkspace.h

performFileOperation:source:destination:files:tag:

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

- (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

YES if the operation succeeded; otherwise, NO.

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.

Availability
  • Available in OS X v10.0 and later.
Declared In
NSWorkspace.h

preferredFilenameExtensionForType:

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

- (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.

Availability
  • Available in OS X v10.5 and later.
Declared In
NSWorkspace.h

recycleURLs:completionHandler:

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

- (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.

Availability
  • Available in OS X v10.6 and later.
Declared In
NSWorkspace.h

runningApplications

Returns an array of NSRunningApplication representing the running apps.

- (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.

Availability
  • Available in OS X v10.6 and later.
Declared In
NSRunningApplication.h

selectFile:inFileViewerRootedAtPath:

Selects the file specified by fullPath.

- (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

YES if the file was successfully selected; otherwise, NO.

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.

Availability
  • Available in OS X v10.0 and later.
Related Sample Code
Declared In
NSWorkspace.h

setDesktopImageURL:forScreen:options:error:

Sets the desktop image for the given screen to the image at the specified URL.

- (BOOL)setDesktopImageURL:(NSURL *)url forScreen:(NSScreen *)screen options:(NSDictionary *)options error:(NSError **)error
Parameters
url

A file URL to the image. The URL must not be nil.

screen

The screen to set the desktop image on.

options

The options dictionary may contain any of the “Desktop Image Dictionary Keys” keys, which control how the image is scaled on the screen.

error

A error that is returned by-reference if setting the image fails.

Return Value

YES if the image was set as the desktop, otherwise NO. If NO is returned, the error parameter provides additional information.

Discussion

You should not present a user interface for picking the options. Instead, choose appropriate defaults and allow the user to adjust them in the System Preference Pane.

You must call this method from your app’s main thread.

Availability
  • Available in OS X v10.6 and later.
Declared In
NSWorkspace.h

setIcon:forFile:options:

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

- (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

YES if the icon was set; otherwise, NO.

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.

Availability
  • Available in OS X v10.4 and later.
Declared In
NSWorkspace.h

showSearchResultsForQueryString:

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

- (BOOL)showSearchResultsForQueryString:(NSString *)queryString
Parameters
queryString

The string to search for.

Return Value

YES if the communication with Finder was successful, otherwise NO.

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.

Availability
  • Available in OS X v10.6 and later.
Declared In
NSWorkspace.h

type:conformsToType:

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

- (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

YES if firstTypeName conforms to the uniform type identifier hierarchy of secondTypeName, NO 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 YES 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.

Availability
  • Available in OS X v10.5 and later.
Related Sample Code
Declared In
NSWorkspace.h

typeOfFile:error:

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

- (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.

Availability
  • Available in OS X v10.5 and later.
Declared In
NSWorkspace.h

unmountAndEjectDeviceAtPath:

Unmounts and ejects the device at the specified path.

- (BOOL)unmountAndEjectDeviceAtPath:(NSString *)path
Parameters
path

The path to the device.

Return Value

YES if the device was unmounted; otherwise, NO.

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.

Availability
  • Available in OS X v10.0 and later.
Related Sample Code
Declared In
NSWorkspace.h

unmountAndEjectDeviceAtURL:error:

Attempts to eject the volume mounted at the given path.

- (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

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

Discussion

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

Availability
  • Available in OS X v10.6 and later.
Declared In
NSWorkspace.h

URLForApplicationToOpenURL:

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

- (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.

Availability
  • Available in OS X v10.6 and later.
Declared In
NSWorkspace.h

URLForApplicationWithBundleIdentifier:

Returns the URL for the app with the specified identifier.

- (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.

Availability
  • Available in OS X v10.6 and later.
Declared In
NSWorkspace.h

Constants

The following table describes keys for an NSDictionary object containing information about an app. This dictionary is returned by activeApplication and launchedApplications, and is also provided in the userInfo of NSWorkspace notifications for app launch and termination.

Note that these constants are considered legacy.

Table 1  userInfo dictionary keys for activeApplication and launchedApplications and notifications for app launch and termination.

Key

Value

@"NSApplicationPath"

The full path to the app, as a NSString object.

@"NSApplicationName"

The app's name, as an NSString object.

@"NSApplicationBundleIdentifier"

The app’s bundle identifier, as an NSString object.

@"NSApplicationProcessIdentifier"

The app's process id, as an NSNumber object.

@"NSApplicationProcessSerialNumberHigh"

The high long of the process serial number (PSN), as an NSNumber object.

@"NSApplicationProcessSerialNumberLow"

The low long of the process serial number (PSN), as an NSNumber object.

File Types

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

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

Plain (untyped) file

Available in OS X v10.0 and later.

Deprecated in OS X v10.6.

Declared in NSWorkspace.h.

NSDirectoryFileType

Directory

Available in OS X v10.0 and later.

Deprecated in OS X v10.6.

Declared in NSWorkspace.h.

NSApplicationFileType

Cocoa app

Available in OS X v10.0 and later.

Deprecated in OS X v10.6.

Declared in NSWorkspace.h.

NSFilesystemFileType

File-system mount point

Available in OS X v10.0 and later.

Deprecated in OS X v10.6.

Declared in NSWorkspace.h.

NSShellCommandFileType

Executable shell command

Available in OS X v10.0 and later.

Deprecated in OS X v10.6.

Declared in NSWorkspace.h.

Declared In
NSWorkspace.h

Workspace Launch Configuration Options

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.

NSString * const NSWorkspaceLaunchConfigurationAppleEvent;
NSString * const NSWorkspaceLaunchConfigurationArguments;
NSString * const NSWorkspaceLaunchConfigurationEnvironment;
NSString * const NSWorkspaceLaunchConfigurationArchitecture;
Constants
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.

Declared in NSWorkspace.h.

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.

Declared in NSWorkspace.h.

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.

Declared in NSWorkspace.h.

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.

Declared in NSWorkspace.h.

File Operations

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

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

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

Available in OS X v10.0 and later.

Declared in NSWorkspace.h.

NSWorkspaceCopyOperation

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

Available in OS X v10.0 and later.

Declared in NSWorkspace.h.

NSWorkspaceLinkOperation

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

Available in OS X v10.0 and later.

Declared in NSWorkspace.h.

NSWorkspaceCompressOperation

Compress file. This operation always returns an error.

Available in OS X v10.0 and later.

Declared in NSWorkspace.h.

NSWorkspaceDecompressOperation

Decompress file. This operation always returns an error.

Available in OS X v10.0 and later.

Declared in NSWorkspace.h.

NSWorkspaceEncryptOperation

Encrypt file. This operation always returns an error.

Available in OS X v10.0 and later.

Declared in NSWorkspace.h.

NSWorkspaceDecryptOperation

Decrypt file. This operation always returns an error.

Available in OS X v10.0 and later.

Declared in NSWorkspace.h.

NSWorkspaceDestroyOperation

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

Available in OS X v10.0 and later.

Declared in NSWorkspace.h.

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.

Declared in NSWorkspace.h.

NSWorkspaceDuplicateOperation

Duplicate file in source directory.

Available in OS X v10.0 and later.

Declared in NSWorkspace.h.

Declared In
NSWorkspace.h

Desktop Image Dictionary Keys

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

NSString * const NSWorkspaceDesktopImageScalingKey;
NSString * const NSWorkspaceDesktopImageAllowClippingKey;
NSString * const NSWorkspaceDesktopImageFillColorKey;
   
   
Constants
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.

Declared in NSWorkspace.h.

NSWorkspaceDesktopImageAllowClippingKey

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

Available in OS X v10.6 and later.

Declared in NSWorkspace.h.

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.

Declared in NSWorkspace.h.

NSWorkspaceLaunchOptions

These constants define launch options you can pass to launchAppWithBundleIdentifier:options:additionalEventParamDescriptor:launchIdentifier: and openURLs:withAppBundleIdentifier:options:additionalEventParamDescriptor:launchIdentifiers:.

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
NSWorkspaceLaunchAndPrint

Print items instead of opening them.

Available in OS X v10.3 and later.

Declared in NSWorkspace.h.

NSWorkspaceLaunchWithErrorPresentation

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

Available in OS X v10.9 and later.

Declared in NSWorkspace.h.

NSWorkspaceLaunchInhibitingBackgroundOnly

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

Available in OS X v10.3 and later.

Declared in NSWorkspace.h.

NSWorkspaceLaunchWithoutAddingToRecents

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

Available in OS X v10.3 and later.

Declared in NSWorkspace.h.

NSWorkspaceLaunchWithoutActivation

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

Available in OS X v10.3 and later.

Declared in NSWorkspace.h.

NSWorkspaceLaunchAsync

Launch the app and return the results asynchronously.

Available in OS X v10.3 and later.

Declared in NSWorkspace.h.

NSWorkspaceLaunchAllowingClassicStartup

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

Available in OS X v10.3 and later.

Declared in NSWorkspace.h.

NSWorkspaceLaunchPreferringClassic

Force the app to launch in the Classic compatibility environment.

Available in OS X v10.3 and later.

Declared in NSWorkspace.h.

NSWorkspaceLaunchNewInstance

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

Available in OS X v10.3 and later.

Declared in NSWorkspace.h.

NSWorkspaceLaunchAndHide

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

Available in OS X v10.3 and later.

Declared in NSWorkspace.h.

NSWorkspaceLaunchAndHideOthers

Hide all apps except the newly launched one.

Available in OS X v10.3 and later.

Declared in NSWorkspace.h.

NSWorkspaceLaunchDefault

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

Available in OS X v10.3 and later.

Declared in NSWorkspace.h.

Volume Mounting Notification User Info Keys

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

NSString * const NSWorkspaceVolumeLocalizedNameKey;
NSString * const NSWorkspaceVolumeURLKey;
Constants
NSWorkspaceVolumeLocalizedNameKey

NSString containing the user-visible name of the volume.

Available in OS X v10.6 and later.

Declared in NSWorkspace.h.

NSWorkspaceVolumeURLKey

NSURL containing the mount path of the volume.

Available in OS X v10.6 and later.

Declared in NSWorkspace.h.

NSWorkspaceDidRenameVolumeNotification User Info Keys

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

NSString * const NSWorkspaceVolumeOldLocalizedNameKey;
NSString * const NSWorkspaceVolumeOldURLKey;
Constants
NSWorkspaceVolumeOldLocalizedNameKey

NSString containing the old user-visible name of the volume

Available in OS X v10.6 and later.

Declared in NSWorkspace.h.

NSWorkspaceVolumeOldURLKey

NSURL containing the old mount path of the volume

Available in OS X v10.6 and later.

Declared in NSWorkspace.h.

NSWorkspaceApplicationKey User Info Key

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

NSString * const NSWorkspaceApplicationKey;
Constants
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.

Declared in NSWorkspace.h.

Workspace icon creation options

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

enum {
   NSExcludeQuickDrawElementsIconCreationOption    = 1 << 1,
   NSExclude10_4ElementsIconCreationOption        = 1 << 2
};
typedef NSUInteger NSWorkspaceIconCreationOptions;
Constants
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.

Declared in NSWorkspace.h.

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.

Declared in NSWorkspace.h.

Notifications

All NSWorkspace notifications are posted to the NSWorkspace object’s own notification center, not the app’s default notification center. Access this center using the NSWorkspace object’s notificationCenter method.

NSWorkspaceWillLaunchApplicationNotification

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.

Availability
Declared In
NSWorkspace.h

NSWorkspaceDidLaunchApplicationNotification

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.

Availability
Declared In
NSWorkspace.h

NSWorkspaceDidTerminateApplicationNotification

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.

Availability
Declared In
NSWorkspace.h

NSWorkspaceSessionDidBecomeActiveNotification

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.

Availability
Declared In
NSWorkspace.h

NSWorkspaceSessionDidResignActiveNotification

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.

Availability
Declared In
NSWorkspace.h

NSWorkspaceDidHideApplicationNotification

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.

Availability
Declared In
NSWorkspace.h

NSWorkspaceDidUnhideApplicationNotification

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.

Availability
Declared In
NSWorkspace.h

NSWorkspaceDidActivateApplicationNotification

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.

Availability
Declared In
NSWorkspace.h

NSWorkspaceDidDeactivateApplicationNotification

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.

Availability
Declared In
NSWorkspace.h

NSWorkspaceDidRenameVolumeNotification

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.”

Availability
Declared In
NSWorkspace.h

NSWorkspaceDidMountNotification

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.

Availability
Declared In
NSWorkspace.h

NSWorkspaceWillUnmountNotification

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.

Availability
Declared In
NSWorkspace.h

NSWorkspaceDidUnmountNotification

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.

Availability
Declared In
NSWorkspace.h

NSWorkspaceDidPerformFileOperationNotification

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

Availability
Declared In
NSWorkspace.h

NSWorkspaceDidChangeFileLabelsNotification

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.

Availability
Declared In
NSWorkspace.h

NSWorkspaceActiveSpaceDidChangeNotification

Posted when a Spaces change has occurred.

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

Availability
Declared In
NSWorkspace.h

NSWorkspaceDidWakeNotification

Posted when the machine wakes from sleep.

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

Availability
Declared In
NSWorkspace.h

NSWorkspaceWillPowerOffNotification

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.

Availability
Declared In
NSWorkspace.h

NSWorkspaceWillSleepNotification

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.

Availability
Declared In
NSWorkspace.h

NSWorkspaceScreensDidSleepNotification

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.

Availability
Declared In
NSWorkspace.h

NSWorkspaceScreensDidWakeNotification

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.

Availability
Declared In
NSWorkspace.h