- Inherits from:
- NSObject
- Package:
- com.apple.yellow.application
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.
These constants specify different types of files:
Constant | Description |
PlainFileType |
Plain (untyped) file |
DirectoryFileType |
Directory |
ApplicationFileType |
Cocoa application |
FilesystemFileType |
File system mount point |
ShellCommandFileType |
Executable shell command |
The constants specify different type of file operations. They're used by performFileOperation.
Constant | Description |
MoveOperation |
Move file to destination |
CopyOperation |
Copy file to destination |
LinkOperation |
Create link to file in destination |
CompressOperation |
Compress file |
DecompressOperation |
Decompress file |
EncryptOperation |
Encrypt file |
DecryptOperation |
Decrypt file |
DestroyOperation |
Destroy file |
RecycleOperation |
Move file to recycler |
DuplicateOperation |
Duplicate file in source directory |
- Constructors
- NSWorkspace
- Accessing the shared NSWorkspace
- sharedWorkspace
- Accessing the NSWorkspace notification center
- notificationCenter
- Opening files
- openFile
- openTempFile
- Manipulating applications
- launchApplication
- hideOtherApplications
- Manipulating files
- applicationForFile
- performFileOperation
- selectFile
- Requesting information about files
- iconForFile
- iconForFileType
- iconForFiles
- fullPathForApplication
- 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
- Unmounting a device
- unmountAndEjectDeviceAtPath
public NSWorkspace()
public static NSWorkspace sharedWorkspace()
public String applicationForFile(String aString)
public void checkForRemovableMedia()
See Also: mountNewRemovableMedia, mountedRemovableMedia
public int extendPowerOffBy(int requested)
public boolean fileSystemChanged()
true
if
a change to the file system has been registered with a noteFileSystemChanged message
since the last fileSystemChanged message; false
otherwise.public void findApplications()
/Network/Applications
, /System/Applications
, /System/Developer/Applications
)
and updates the records of registered services and file types.public String fullPathForApplication(String appName)
null
if appName isn't
in one of the normal places.public void hideOtherApplications()
public NSImage iconForFile(String fullPath)
See Also: getInfoForFile:application:type:, iconForFileType, iconForFiles
public NSImage iconForFileType(String fileType)
See Also: iconForFile, iconForFiles
public NSImage iconForFiles(NSArray fullPaths)
See Also: iconForFile, iconForFileType
public boolean launchApplication(
String appName,
boolean showIcon,
boolean autoLaunch)
true
,
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 true
if
the application is successfully launched or already running, and false
if
it can't be launched.
Before this method begins, it posts a WorkspaceWillLaunchApplicationNotification to the NSWorkspace's notification center. When the operation is complete, it posts a WorkspaceDidLaunchApplicationNotification.
public boolean launchApplication(String appName)
.app
extension.
Returns true
if the application is
successfully launched or already running, false
if
it can't be launched.Before this method begins, it posts a WorkspaceWillLaunchApplicationNotification to the NSWorkspace's notification center. When the operation is complete, it posts a WorkspaceDidLaunchApplicationNotification.
public NSArray mountNewRemovableMedia()
See Also: checkForRemovableMedia, mountedRemovableMedia
public 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
public void noteFileSystemChanged()
See Also: fileSystemChanged
public void noteUserDefaultsChanged()
See Also: userDefaultsChanged
public NSNotificationCenter notificationCenter()
public boolean openFile(
String fullPath,
String appName,
boolean flag)
.app
extension. If appName is null
,
the default application for the file's type is used. If flag is true
,
the sending application is deactivated before the request is sent,
allowing the opening application to become the active application.
Returns true
if the file is successfully
opened, false
otherwise.
public boolean openFile(
String fullPath,
String appName)
.app
extension. The
sending application is deactivated before the request is sent. Returns true
if
the file is successfully opened, false otherwise.
public boolean openFile(
String fullPath,
NSImage anImage,
NSPoint point,
NSView aView)
The
sending application is deactivated before the request is sent. Returns true
if
the file is successfully opened, false otherwise.
public boolean openFile(String fullPath)
true
if
the file was successfully opened, false
otherwise. The
sending application is deactivated before the request is sent.public boolean openTempFile(String fullPath)
true
if
the file is successfully opened, false
otherwise.See Also: openFile
public int performFileOperation(
String operation,
String source,
String destination,
NSArray files)
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 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 identifies the requested file operation. Before this method returns, it posts a WorkspaceDidPerformFileOperationNotification to NSWorkspace's notification center.
public boolean selectFile(
String fullPath,
String rootFullPath)
true
if the file
is successfully selected, false
otherwise.public void slideImage(
NSImage image,
NSPoint fromPoint,
NSPoint toPoint)
public boolean unmountAndEjectDeviceAtPath(String path)
true
if
the unmount operation succeeded, false
otherwise.
When this method begins, it posts a WorkspaceWillUnmountNotification
to NSWorkspace's notification center. When it is finished, it
posts a WorkspaceDidUnmountNotification.public boolean 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 |
ApplicationName |
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 |
DevicePath |
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 |
OperationNumber |
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 |
ApplicationName |
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 |
DevicePath |
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 |
ApplicationName |
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 |
DevicePath |
The path where the device is mounted |