- Inherits from:
- NSObject
- Conforms to:
- NSObject
- (NSObject)
Declared in:
- AppKit/NSWorkspace.h
An NSWorkspace object responds to application requests to perform a variety of services:
There is one shared NSWorkspace object per application. 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 Edit application:
[[NSWorkspace sharedWorkspace] openFile:@"/Myfiles/README" withApplication:@"Edit"];
These constants specify different types of files returned by getInfoForFile:application:type::
Constant | Description |
NSPlainFileType |
Plain (untyped) file |
NSDirectoryFileType |
Directory |
NSApplicationFileType |
Cocoa application |
NSFilesystemFileType |
File system mount point |
NSShellCommandFileType |
Executable shell command |
The constants specify different type of file operations. They're used by performFileOperation:source:destination:files:tag:.
Constant | Description |
NSWorkspaceMoveOperation |
Move file to destination |
NSWorkspaceCopyOperation |
Copy file to destination |
NSWorkspaceLinkOperation |
Create link to file in destination |
NSWorkspaceCompressOperation |
Compress file |
NSWorkspaceDecompressOperation |
Decompress file |
NSWorkspaceEncryptOperation |
Encrypt file |
NSWorkspaceDecryptOperation |
Decrypt file |
NSWorkspaceDestroyOperation |
Destroy file |
NSWorkspaceRecycleOperation |
Move file to recycler |
NSWorkspaceDuplicateOperation |
Duplicate file in source directory |
- Accessing the shared NSWorkspace
- + sharedWorkspace
- Accessing the NSWorkspace notification center
- - notificationCenter
- Opening files
- - openFile:
- - openFile:withApplication:
- - openFile:fromImage:at:inView:
- - openFile:withApplication:andDeactivate:
- - openTempFile:
- Manipulating applications
- - launchApplication:
- - launchApplication:showIcon:autolaunch:
- - hideOtherApplications
- Manipulating files
- - performFileOperation:source:destination:files:tag:
- - selectFile:inFileViewerRootedAtPath:
- Requesting information about files
- - iconForFile:
- - iconForFileType:
- - iconForFiles:
- - getInfoForFile:application:type:
- - fullPathForApplication:
- - getFileSystemInfoForPath:isRemovable:isWritable:isUnmountable:description:type:
- Requesting additional time before logout
- - extendPowerOffBy:
- Tracking changes to the file system
- - noteFileSystemChanged
- - fileSystemChanged
- Updating registered services and file types
- - findApplications
- Tracking changes to the defaults database
- - noteUserDefaultsChanged
- - userDefaultsChanged
- Tracking status changes for applications and devices
- - mountedRemovableMedia
- - mountNewRemovableMedia
- - checkForRemovableMedia
- Animating an image
- - slideImage:from:to:
- Unmounting a device
- - unmountAndEjectDeviceAtPath:
+ (NSWorkspace *)sharedWorkspace
- (void)checkForRemovableMedia
See Also: - mountNewRemovableMedia, - mountedRemovableMedia
- (int)extendPowerOffBy:(int)requested
- (BOOL)fileSystemChanged
YES
if
a change to the file system has been registered with a noteFileSystemChanged message
since the last fileSystemChanged message; NO
otherwise.- (void)findApplications
/Network/Applications
, /System/Applications
, /System/Developer/Applications
)
and updates the records of registered services and file types.- (NSString *)fullPathForApplication:(NSString
*)appName
nil
if appName isn't
in one of the normal places.- (BOOL)getFileSystemInfoForPath:(NSString
*)fullPath
isRemovable:(BOOL *)removableFlag
isWritable:(BOOL *)writableFlag
isUnmountable:(BOOL *)unmountableFlag
description:(NSString **)description
type:(NSString **)fileSystemType
Returns YES
if fullPath is
a file system mount point, NO
otherwise.
If the return value is YES
, description describes
the file system; this value can be used in strings, but shouldn't
be depended upon by program logic. Example values for description
are "hard," "nfs," and "foreign." fileSystemType indicates
the file system type; values could be "HFS," "UFS," or other
values. removableFlag is YES
if
the file system is on removable media, NO otherwise. writableFlag is YES
if
the file system's media is writable, NO
otherwise. unmountableFlag returns YES
if
the file system is unmountable, NO
otherwise.
- (BOOL)getInfoForFile:(NSString
*)fullPath
application:(NSString **)appName
type:(NSString **)type
YES
, the NSString pointed
to by appName is set to the application
the system would use to open fullPath.
The NSString pointed to by type contains
one of the values described in "Constants" .This method returns NO if it could not find fullPath.
See Also: - iconForFile:, - iconForFiles:
- (void)hideOtherApplications
- (NSImage *)iconForFile:(NSString
*)fullPath
See Also: - getInfoForFile:application:type:, - iconForFileType:, - iconForFiles:
- (NSImage *)iconForFileType:(NSString
*)fileType
See Also: - iconForFile:, - iconForFiles:
- (NSImage *)iconForFiles:(NSArray
*)fullPaths
See Also: - iconForFile:, - iconForFileType:
- (BOOL)launchApplication:(NSString
*)appName
.app
extension.
Returns YES
if the application is
successfully launched or already running, NO
if
it can't be launched.Before this method begins, it posts an NSWorkspaceWillLaunchApplicationNotification to the NSWorkspace's notification center. When the operation is complete, it posts an NSWorkspaceDidLaunchApplicationNotification.
See Also: - launchApplication:showIcon:autolaunch:
- (BOOL)launchApplication:(NSString
*)appName
showIcon:(BOOL)showIcon
autolaunch:(BOOL)autolaunch
NO
,
the application's icon won't be placed on the screen. (The icon
still exists, though.) If autolaunch is YES
,
the autolaunch default will be set as though the application were
autolaunched at startup. This method is provided to enable daemon-like applications
that lack a normal user interface. Its use is not generally encouraged.Returns YES
if
the application 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's notification center. When the operation is complete, it posts an NSWorkspaceDidLaunchApplicationNotification.
See Also: - launchApplication:
- (NSArray *)mountNewRemovableMedia
See Also: - checkForRemovableMedia, - mountedRemovableMedia
- (NSArray *)mountedRemovableMedia
If the computer provides an interrupt or other notification when the user inserts a disk into a drive, the Workspace Manager will mount the disk immediately. However, if no notification is given, the Workspace Manager won't be aware that a disk needs to be mounted. On such systems, an application should invoke either mountNewRemovableMedia or checkForRemovableMedia before invoking mountedRemovableMedia. Either of these methods cause the Workspace Manager 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 Workspace Manager to mount it.
The Disk button in an Open or Save panel invokes mountedRemovableMedia and mountNewRemovableMedia as part of its operation, so most applications won't need to invoke these methods directly.
See Also: - checkForRemovableMedia, - mountNewRemovableMedia
- (void)noteFileSystemChanged
See Also: - fileSystemChanged
- (void)noteUserDefaultsChanged
See Also: - userDefaultsChanged
- (NSNotificationCenter *)notificationCenter
- (BOOL)openFile:(NSString
*)fullPath
YES
if
the file was successfully opened, NO
otherwise. The
sending application is deactivated before the request is sent.See Also: - openFile:fromImage:at:inView:, - openFile:withApplication:, - openFile:withApplication:andDeactivate:, - openTempFile:
- (BOOL)openFile:(NSString
*)fullPath
fromImage:(NSImage *)anImage
at:(NSPoint)point
inView:(NSView *)aView
The
sending application is deactivated before the request is sent. Returns YES
if
the file is successfully opened, NO otherwise.
See Also: - openFile:, - openFile:withApplication:, - openFile:withApplication:andDeactivate:, - openTempFile:
- (BOOL)openFile:(NSString
*)fullPath
withApplication:(NSString *)appName
.app
extension. The
sending application is deactivated before the request is sent. Returns YES
if
the file is successfully opened, NO otherwise.See Also: - openFile:, - openFile:withApplication:andDeactivate:
- (BOOL)openFile:(NSString
*)fullPath
withApplication:(NSString *)appName
andDeactivate:(BOOL)flag
.app
extension. If appName is nil
,
the default application for the file's type is used. If flag is YES
,
the sending application is deactivated before the request is sent,
allowing the opening application to become the active application.
Returns YES
if the file is successfully
opened, NO
otherwise.See Also: - openFile:, - openFile:withApplication:, - application:openFile: (NSApplication delegate method)
- (BOOL)openTempFile:(NSString
*)fullPath
YES
if the file
is successfully opened, NO
otherwise.See Also: - openFile:, - openFile:fromImage:at:inView:, - openFile:withApplication:, - openFile:withApplication:andDeactivate:
- (BOOL)performFileOperation:(NSString
*)operation
source:(NSString *)source
destination:(NSString *)destination
files:(NSArray *)files
tag:(int *)tag
Some operations-such as moving, copying, and linking files-require a destination directory to be specified. If not, destination should be the empty string (@"").
The possible values for operation are described in "Constants" .
This
method returns YES
if the operation
succeeded, NO
otherwise. In tag,
the method returns a negative integer if the operation fails, 0
if the operation is performed synchronously and succeeds, and a
positive integer if the operation is performed asynchronously. The
positive integer is a tag that identifies the requested file operation.
Before this method returns, it posts an NSWorkspaceDidPerformFileOperationNotification
to NSWorkspace's notification center.
- (BOOL)selectFile:(NSString
*)fullPath
inFileViewerRootedAtPath:(NSString
*)rootFullPath
YES
if the file is
successfully selected, NO
otherwise.- (void)slideImage:(NSImage
*)image
from:(NSPoint)fromPoint
to:(NSPoint)toPoint
- (BOOL)unmountAndEjectDeviceAtPath:(NSString
*)path
YES
if
the unmount operation succeeded, NO
otherwise.
When this method begins, it posts an NSWorkspaceWillUnmountNotification
to NSWorkspace's notification center. When it is finished, it
posts an NSWorkspaceDidUnmountNotification.- (BOOL)userDefaultsChanged
All NSWorkspace notifications are posted to NSWorkspace's own notification center, not the application's default notification center. Access this center using NSWorkspace's notificationCenter method.
Posted when a new application has started up.
This notification contains a notification object and a userInfo dictionary. The notification object is the shared NSWorkspace instance. The userInfo dictionary contains these keys and values:
Key | Value |
NSApplicationName |
The application being terminated |
Posted when a new device has been mounted.
This notification contains a notification object and a userInfo dictionary. The notification object is the shared NSWorkspace instance. The userInfo dictionary contains these keys and values:
Key | Value |
NSDevicePath |
The path where the device was mounted |
Posted when a file operation has been performed.
This notification contains a notification object and a userInfo dictionary. The notification object is the shared NSWorkspace instance. The userInfo dictionary contains these keys and values:
Key | Value |
NSOperationNumber |
A number indicating the type of file operation completed |
Posted when an application finishes executing.
This notification contains a notification object and a userInfo dictionary. The notification object is the shared NSWorkspace instance. The userInfo dictionary contains these keys and values:
Key | Value |
NSApplicationName |
The application that terminated |
Posted when the workspace has unmounted a device.
This notification contains a notification object and a userInfo dictionary. The notification object is the shared NSWorkspace instance. The userInfo dictionary contains these keys and values:
Key | Value |
NSDevicePath |
The path where the device was previously mounted |
Posted when the workspace is about to launch an application.
This notification contains a notification object and a userInfo dictionary. The notification object is the shared NSWorkspace instance. The userInfo dictionary contains these keys and values:
Key | Value |
NSApplicationName |
The application about to be launched |
Posted when the user has requested a logout or that the machine be powered off.
This notification contains a notification object but no userInfo dictionary. The notification object is the shared NSWorkspace instance.
Posted when the workspace is about to unmount a device.
This notification contains a notification object and a userInfo dictionary. The notification object is the shared NSWorkspace instance. The userInfo dictionary contains these keys and values:
Key | Value |
NSDevicePath |
The path where the device is mounted |