An NSWorkspace object can launch other apps and perform a variety of file-handling services.
Language
- Swift
- Objective-C
SDK
- macOS 10.10+
Overview
There is one shared NSWorkspace object per app. You use the class method shared() 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"];
You can use the workspace object to:
Open, manipulate, and get information about files and devices
Track changes to the file system, devices, and the user database
Get and set Finder information for files
Launch apps
Legacy Constants
Table 1 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.
Note
It is strongly suggested that you use the NSWorkspace class’s runningApplications method and the NSRunningApplication class to retrieve this information in apps target macOS 10.6 and later, rather than the activeApplication() and launchedApplications methods.
userInfo dictionary keys for activeApplication and launchedApplications and notifications for app launch and termination
Key |
Value |
|---|---|
|
The full path to the app, as a |
|
The app's name, as an |
|
The app’s bundle identifier, as an |
|
The app's process id, as an |
|
The high long of the process serial number (PSN), as an |
|
The low long of the process serial number (PSN), as an |