Platforms to show: All Mac Windows Linux Cross-Platform

Back to NSWorkspaceMBS class.

Previous items

NSWorkspaceMBS.selectFile(file as folderitem) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method Cocoa MBS MacCocoa Plugin 8.1 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
Selects the file in the Finder.
Example
dim f as FolderItem

f=SpecialFolder.Desktop.Child("test.txt")

if NSWorkspaceMBS.selectFile(f) then
MsgBox "Ok"
else
MsgBox "failed"
end if

Returns true on success.

For Windows, please use WinOpenFolderAndSelectItemsMBS function.

Some examples using this method:

NSWorkspaceMBS.setDesktopImageURL(file as folderitem, screen as NSScreenMBS, options as dictionary, byref error as NSErrorMBS) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method Cocoa MBS MacCocoa Plugin 11.3 ✅ Yes ❌ No ❌ No ❌ No Desktop only
Sets the desktop image for the given screen to the image at the specified URL.

file: The image file. The file 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 (NSWorkspaceDesktopImageScalingKey, NSWorkspaceDesktopImageAllowClippingKey or NSWorkspaceDesktopImageFillColorKey), which control how the image is scaled on the screen.
error: A error that is returned by-reference if setting the image fails.

Returns true if the image was set as the desktop, otherwise false. If false is returned, the error parameter provides additional information.

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.

Available in Mac OS X v10.6 and later.

NSWorkspaceMBS.setIcon(image as NSImageMBS, file as folderitem, flags as Integer = 0) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method Cocoa MBS MacCocoa Plugin 8.1 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
Sets the icon for the file or directory at the specified path.
Example
dim f as FolderItem
dim p as Picture
dim img as NSImageMBS

f=SpecialFolder.Desktop.Child("test.txt")

p=New Picture(128,128,32)
p.Graphics.ForeColor=rgb(0,128,0)
p.Graphics.fillrect 0,0,128,128
p.Graphics.ForeColor=rgb(255,0,0)
p.Graphics.filloval 0,0,128,128

img=new NSImageMBS(p)

if NSWorkspaceMBS.setIcon(img,f,0) then
MsgBox "Ok. Icon may not be visible directly. Maybe you make a copy of the file to see it directly?"
else
MsgBox "failed"
end if

image: The image to use as the icon for the file or directory.
file: The full path of the file or directory.
flags: The icon representations to generate from the image. You specify this value by combining the appropriate NSWorkspaceIconCreationOptions constants, listed in Constants, using the C bitwise OR operator. Specify 0 if you want to generate icons in all available icon representation formats.

Returns true if the icon was set; otherwise, false.

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.

It is recommended that applications include the NSExclude10_4ElementsIconCreationOption option for compatibility with pre-Mac OS X v10.3 Finder. Icons that include the high resolution elements prevent custom icons from being displayed on earlier systems.

Before setting icon, make sure you close all Binarystream, Textoutputstream or other classes which may have the file open.

See also:

NSWorkspaceMBS.setIcon(image as NSImageMBS, path as string, flags as Integer = 0) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method Cocoa MBS MacCocoa Plugin 8.1 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
Sets the icon for the file or directory at the specified path.

image: The image to use as the icon for the file or directory.
path: The full path of the file or directory.
flags: The icon representations to generate from the image. You specify this value by combining the appropriate NSWorkspaceIconCreationOptions constants, listed in Constants, using the C bitwise OR operator. Specify 0 if you want to generate icons in all available icon representation formats.

Returns true if the icon was set; otherwise, false.

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.

It is recommended that applications include the NSExclude10_4ElementsIconCreationOption option for compatibility with pre-Mac OS X v10.3 Finder. Icons that include the high resolution elements prevent custom icons from being displayed on earlier systems.

Before setting icon, make sure you close all Binarystream, Textoutputstream or other classes which may have the file open.

See also:

NSWorkspaceMBS.showSearchResultsForQueryString(queryString as string) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method Cocoa MBS MacCocoa Plugin 9.6 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
Displays a Spotlight search results window in Finder for the specified query string.

Returns true if the communication with Finder was successful, otherwise false.

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

Available in Mac OS X v10.6 and later.

NSWorkspaceMBS.typeOfFile(File as folderitem, byref error as NSErrorMBS) as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method Cocoa MBS MacCocoa Plugin 12.5 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
Returns the uniform type identifier of the specified file, if it can be determined.

file: The absolute path of the file.
Error: If the Uniform Type Identifier of the file at absolutePath can't be determined, outError contains an NSError object that describes why.

Returns a string containing the uniform type identifier of the file at absoluteFilePath. If no UTI can be determined the return value is "".

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

See also:

NSWorkspaceMBS.typeOfFile(Path as string, byref error as NSErrorMBS) as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method Cocoa MBS MacCocoa Plugin 12.5 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
Returns the uniform type identifier of the specified file, if it can be determined.

file: The absolute path of the file.
Error: If the Uniform Type Identifier of the file at absolutePath can't be determined, outError contains an NSError object that describes why.

Returns a string containing the uniform type identifier of the file at absoluteFilePath. If no UTI can be determined the return value is "".

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

See also:

NSWorkspaceMBS.unmountAndEjectDevice(item as folderitem, byref e as NSErrorMBS) as boolean

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method Cocoa MBS MacCocoa Plugin 11.3 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
Unmounts and ejects the device at the specified path.
Example
dim w as new NSWorkspaceMBS
dim disk as FolderItem = Volume(VolumeCount-1)

MsgBox disk.Name

dim e as NSErrorMBS
if w.unmountAndEjectDevice(disk, e) then
MsgBox "OK"
else
MsgBox "Error: "+e.localizedDescription
end if

Returns true if the volume was unmounted and ejected successfully, otherwise false, for example, if the volume is not ejectable.
error: If the operation fails, this error contains more information about the failure.

NSWorkspaceMBS.URLForApplicationToOpenURL(url as string) as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method Cocoa MBS MacCocoa Plugin 12.5 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
Returns the URL to the default application that would be used to open the given URL.

url: The URL of the file to open.

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

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

NSWorkspaceMBS.URLForApplicationWithBundleIdentifier(bundleIdentifier as string) as string

Type Topic Plugin Version macOS Windows Linux iOS Targets
shared method Cocoa MBS MacCocoa Plugin 12.5 ✅ Yes ❌ No ❌ No ❌ No Desktop, Console & Web
Returns the URL for the application with the specified identifier.

bundleIdentifier: A bundle identifier specifying an application.

Returns the URL of the application, or "" if no application has the bundle identifier.
This uses various (currently unspecified) heuristics in case multiple apps have the same bundle ID.

Previous items

The items on this page are in the following plugins: MBS MacCocoa Plugin.


The biggest plugin in space...