#[repr(C)]pub struct NSWorkspace { /* private fields */ }
NSWorkspace
only.Expand description
Implementations§
Source§impl NSWorkspace
NSWorkspaceAccessibilityDisplay.
impl NSWorkspace
NSWorkspaceAccessibilityDisplay.
pub unsafe fn accessibilityDisplayShouldIncreaseContrast(&self) -> bool
NSAccessibility
only.pub unsafe fn accessibilityDisplayShouldDifferentiateWithoutColor(&self) -> bool
NSAccessibility
only.pub unsafe fn accessibilityDisplayShouldReduceTransparency(&self) -> bool
NSAccessibility
only.pub unsafe fn accessibilityDisplayShouldReduceMotion(&self) -> bool
NSAccessibility
only.pub unsafe fn accessibilityDisplayShouldInvertColors(&self) -> bool
NSAccessibility
only.Source§impl NSWorkspace
NSWorkspaceAccessibility.
impl NSWorkspace
NSWorkspaceAccessibility.
pub unsafe fn isVoiceOverEnabled(&self) -> bool
NSAccessibility
only.pub unsafe fn isSwitchControlEnabled(&self) -> bool
NSAccessibility
only.Source§impl NSWorkspace
NSWorkspaceRunningApplications.
impl NSWorkspace
NSWorkspaceRunningApplications.
Sourcepub unsafe fn runningApplications(
&self,
) -> Retained<NSArray<NSRunningApplication>>
Available on crate feature NSRunningApplication
only.
pub unsafe fn runningApplications( &self, ) -> Retained<NSArray<NSRunningApplication>>
NSRunningApplication
only.Returns: An array of NSRunningApplication
s representing currently running applications.
The order of the array is unspecified, but it is stable, meaning that the relative order of particular applications will not change across multiple calls to runningApplications
.
Similar to NSRunningApplication
’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.
This property is thread safe, in that it may be called from background threads and the result is returned atomically. This property is observable through KVO.
Source§impl NSWorkspace
impl NSWorkspace
pub unsafe fn notificationCenter(&self) -> Retained<NSNotificationCenter>
pub unsafe fn openURL(&self, url: &NSURL) -> bool
pub unsafe fn openURL_configuration_completionHandler( &self, url: &NSURL, configuration: &NSWorkspaceOpenConfiguration, completion_handler: Option<&DynBlock<dyn Fn(*mut NSRunningApplication, *mut NSError)>>, )
NSRunningApplication
and block2
only.pub unsafe fn openURLs_withApplicationAtURL_configuration_completionHandler( &self, urls: &NSArray<NSURL>, application_url: &NSURL, configuration: &NSWorkspaceOpenConfiguration, completion_handler: Option<&DynBlock<dyn Fn(*mut NSRunningApplication, *mut NSError)>>, )
NSRunningApplication
and block2
only.pub unsafe fn openApplicationAtURL_configuration_completionHandler( &self, application_url: &NSURL, configuration: &NSWorkspaceOpenConfiguration, completion_handler: Option<&DynBlock<dyn Fn(*mut NSRunningApplication, *mut NSError)>>, )
NSRunningApplication
and block2
only.pub unsafe fn selectFile_inFileViewerRootedAtPath( &self, full_path: Option<&NSString>, root_full_path: &NSString, ) -> bool
pub unsafe fn activateFileViewerSelectingURLs( &self, file_ur_ls: &NSArray<NSURL>, )
pub unsafe fn showSearchResultsForQueryString( &self, query_string: &NSString, ) -> bool
pub unsafe fn noteFileSystemChanged_(&self, path: &NSString)
pub unsafe fn isFilePackageAtPath(&self, full_path: &NSString) -> bool
pub unsafe fn iconForFile(&self, full_path: &NSString) -> Retained<NSImage>
NSImage
only.pub unsafe fn iconForFiles( &self, full_paths: &NSArray<NSString>, ) -> Option<Retained<NSImage>>
NSImage
only.pub unsafe fn iconForContentType( &self, content_type: &UTType, ) -> Retained<NSImage>
NSImage
and crate feature objc2-uniform-type-identifiers
and Apple only.pub unsafe fn setIcon_forFile_options( &self, image: Option<&NSImage>, full_path: &NSString, options: NSWorkspaceIconCreationOptions, ) -> bool
NSImage
only.pub unsafe fn fileLabels(&self) -> Retained<NSArray<NSString>>
pub unsafe fn fileLabelColors(&self) -> Retained<NSArray<NSColor>>
NSColor
only.pub unsafe fn recycleURLs_completionHandler( &self, ur_ls: &NSArray<NSURL>, handler: Option<&DynBlock<dyn Fn(NonNull<NSDictionary<NSURL, NSURL>>, *mut NSError)>>, )
block2
only.pub unsafe fn duplicateURLs_completionHandler( &self, ur_ls: &NSArray<NSURL>, handler: Option<&DynBlock<dyn Fn(NonNull<NSDictionary<NSURL, NSURL>>, *mut NSError)>>, )
block2
only.pub unsafe fn getFileSystemInfoForPath_isRemovable_isWritable_isUnmountable_description_type( &self, full_path: &NSString, removable_flag: *mut Bool, writable_flag: *mut Bool, unmountable_flag: *mut Bool, description: Option<&mut Option<Retained<NSString>>>, file_system_type: Option<&mut Option<Retained<NSString>>>, ) -> bool
pub unsafe fn unmountAndEjectDeviceAtPath(&self, path: &NSString) -> bool
pub unsafe fn unmountAndEjectDeviceAtURL_error( &self, url: &NSURL, ) -> Result<(), Retained<NSError>>
pub unsafe fn extendPowerOffBy(&self, requested: NSInteger) -> NSInteger
pub unsafe fn hideOtherApplications(&self)
pub unsafe fn URLForApplicationWithBundleIdentifier( &self, bundle_identifier: &NSString, ) -> Option<Retained<NSURL>>
pub unsafe fn URLsForApplicationsWithBundleIdentifier( &self, bundle_identifier: &NSString, ) -> Retained<NSArray<NSURL>>
pub unsafe fn URLForApplicationToOpenURL( &self, url: &NSURL, ) -> Option<Retained<NSURL>>
pub unsafe fn URLsForApplicationsToOpenURL( &self, url: &NSURL, ) -> Retained<NSArray<NSURL>>
pub unsafe fn setDefaultApplicationAtURL_toOpenContentTypeOfFileAtURL_completionHandler( &self, application_url: &NSURL, url: &NSURL, completion_handler: Option<&DynBlock<dyn Fn(*mut NSError)>>, )
block2
only.pub unsafe fn setDefaultApplicationAtURL_toOpenURLsWithScheme_completionHandler( &self, application_url: &NSURL, url_scheme: &NSString, completion_handler: Option<&DynBlock<dyn Fn(*mut NSError)>>, )
block2
only.pub unsafe fn setDefaultApplicationAtURL_toOpenFileAtURL_completionHandler( &self, application_url: &NSURL, url: &NSURL, completion_handler: Option<&DynBlock<dyn Fn(*mut NSError)>>, )
block2
only.pub unsafe fn URLForApplicationToOpenContentType( &self, content_type: &UTType, ) -> Option<Retained<NSURL>>
objc2-uniform-type-identifiers
and Apple only.pub unsafe fn URLsForApplicationsToOpenContentType( &self, content_type: &UTType, ) -> Retained<NSArray<NSURL>>
objc2-uniform-type-identifiers
and Apple only.pub unsafe fn setDefaultApplicationAtURL_toOpenContentType_completionHandler( &self, application_url: &NSURL, content_type: &UTType, completion_handler: Option<&DynBlock<dyn Fn(*mut NSError)>>, )
block2
and crate feature objc2-uniform-type-identifiers
and Apple only.pub unsafe fn frontmostApplication( &self, ) -> Option<Retained<NSRunningApplication>>
NSRunningApplication
only.NSRunningApplication
only.Source§impl NSWorkspace
Methods declared on superclass NSObject
.
impl NSWorkspace
Methods declared on superclass NSObject
.
Source§impl NSWorkspace
NSDesktopImages.
impl NSWorkspace
NSDesktopImages.
pub unsafe fn setDesktopImageURL_forScreen_options_error( &self, url: &NSURL, screen: &NSScreen, options: &NSDictionary<NSWorkspaceDesktopImageOptionKey, AnyObject>, ) -> Result<(), Retained<NSError>>
NSScreen
only.pub unsafe fn desktopImageURLForScreen( &self, screen: &NSScreen, ) -> Option<Retained<NSURL>>
NSScreen
only.pub unsafe fn desktopImageOptionsForScreen( &self, screen: &NSScreen, ) -> Option<Retained<NSDictionary<NSWorkspaceDesktopImageOptionKey, AnyObject>>>
NSScreen
only.Source§impl NSWorkspace
NSWorkspaceAuthorization.
impl NSWorkspace
NSWorkspaceAuthorization.
pub unsafe fn requestAuthorizationOfType_completionHandler( &self, type: NSWorkspaceAuthorizationType, completion_handler: &DynBlock<dyn Fn(*mut NSWorkspaceAuthorization, *mut NSError)>, )
block2
only.Source§impl NSWorkspace
NSDeprecated.
impl NSWorkspace
NSDeprecated.
pub unsafe fn openFile(&self, full_path: &NSString) -> bool
pub unsafe fn openFile_withApplication( &self, full_path: &NSString, app_name: Option<&NSString>, ) -> bool
pub unsafe fn openFile_withApplication_andDeactivate( &self, full_path: &NSString, app_name: Option<&NSString>, flag: bool, ) -> bool
pub unsafe fn launchApplication(&self, app_name: &NSString) -> bool
pub unsafe fn launchApplicationAtURL_options_configuration_error( &self, url: &NSURL, options: NSWorkspaceLaunchOptions, configuration: &NSDictionary<NSWorkspaceLaunchConfigurationKey, AnyObject>, ) -> Result<Retained<NSRunningApplication>, Retained<NSError>>
NSRunningApplication
only.pub unsafe fn openURL_options_configuration_error( &self, url: &NSURL, options: NSWorkspaceLaunchOptions, configuration: &NSDictionary<NSWorkspaceLaunchConfigurationKey, AnyObject>, ) -> Result<Retained<NSRunningApplication>, Retained<NSError>>
NSRunningApplication
only.pub unsafe fn openURLs_withApplicationAtURL_options_configuration_error( &self, urls: &NSArray<NSURL>, application_url: &NSURL, options: NSWorkspaceLaunchOptions, configuration: &NSDictionary<NSWorkspaceLaunchConfigurationKey, AnyObject>, ) -> Result<Retained<NSRunningApplication>, Retained<NSError>>
NSRunningApplication
only.pub unsafe fn launchApplication_showIcon_autolaunch( &self, app_name: &NSString, show_icon: bool, autolaunch: bool, ) -> bool
pub unsafe fn fullPathForApplication( &self, app_name: &NSString, ) -> Option<Retained<NSString>>
pub unsafe fn absolutePathForAppBundleWithIdentifier( &self, bundle_identifier: &NSString, ) -> Option<Retained<NSString>>
pub unsafe fn launchAppWithBundleIdentifier_options_additionalEventParamDescriptor_launchIdentifier( &self, bundle_identifier: &NSString, options: NSWorkspaceLaunchOptions, descriptor: Option<&NSAppleEventDescriptor>, identifier: Option<&mut Option<Retained<NSNumber>>>, ) -> bool
pub unsafe fn openURLs_withAppBundleIdentifier_options_additionalEventParamDescriptor_launchIdentifiers( &self, urls: &NSArray<NSURL>, bundle_identifier: Option<&NSString>, options: NSWorkspaceLaunchOptions, descriptor: Option<&NSAppleEventDescriptor>, identifiers: Option<&mut Option<Retained<NSArray<NSNumber>>>>, ) -> bool
pub unsafe fn openTempFile(&self, full_path: &NSString) -> bool
pub unsafe fn findApplications(&self)
pub unsafe fn noteUserDefaultsChanged(&self)
pub unsafe fn slideImage_from_to( &self, image: &NSImage, from_point: NSPoint, to_point: NSPoint, )
NSImage
only.pub unsafe fn checkForRemovableMedia(&self)
pub unsafe fn noteFileSystemChanged(&self)
pub unsafe fn fileSystemChanged(&self) -> bool
pub unsafe fn userDefaultsChanged(&self) -> bool
pub unsafe fn mountNewRemovableMedia(&self) -> Option<Retained<NSArray>>
pub unsafe fn activeApplication(&self) -> Option<Retained<NSDictionary>>
pub unsafe fn mountedLocalVolumePaths(&self) -> Option<Retained<NSArray>>
pub unsafe fn mountedRemovableMedia(&self) -> Option<Retained<NSArray>>
pub unsafe fn launchedApplications(&self) -> Option<Retained<NSArray>>
pub unsafe fn openFile_fromImage_at_inView( &self, full_path: &NSString, image: Option<&NSImage>, point: NSPoint, view: Option<&NSView>, ) -> bool
NSImage
and NSResponder
and NSView
only.pub unsafe fn performFileOperation_source_destination_files_tag( &self, operation: &NSWorkspaceFileOperationName, source: &NSString, destination: &NSString, files: &NSArray, tag: *mut NSInteger, ) -> bool
pub unsafe fn getInfoForFile_application_type( &self, full_path: &NSString, app_name: Option<&mut Option<Retained<NSString>>>, type: Option<&mut Option<Retained<NSString>>>, ) -> bool
pub unsafe fn iconForFileType(&self, file_type: &NSString) -> Retained<NSImage>
NSImage
only.pub unsafe fn typeOfFile_error( &self, absolute_file_path: &NSString, ) -> Result<Retained<NSString>, Retained<NSError>>
pub unsafe fn localizedDescriptionForType( &self, type_name: &NSString, ) -> Option<Retained<NSString>>
pub unsafe fn preferredFilenameExtensionForType( &self, type_name: &NSString, ) -> Option<Retained<NSString>>
pub unsafe fn filenameExtension_isValidForType( &self, filename_extension: &NSString, type_name: &NSString, ) -> bool
pub unsafe fn type_conformsToType( &self, first_type_name: &NSString, second_type_name: &NSString, ) -> bool
Methods from Deref<Target = NSObject>§
Sourcepub fn doesNotRecognizeSelector(&self, sel: Sel) -> !
pub fn doesNotRecognizeSelector(&self, sel: Sel) -> !
Handle messages the object doesn’t recognize.
See Apple’s documentation for details.
Methods from Deref<Target = AnyObject>§
Sourcepub fn class(&self) -> &'static AnyClass
Available on crate feature NSAccessibilityConstants
only.
pub fn class(&self) -> &'static AnyClass
NSAccessibilityConstants
only.Dynamically find the class of this object.
§Panics
May panic if the object is invalid (which may be the case for objects
returned from unavailable init
/new
methods).
§Example
Check that an instance of NSObject
has the precise class NSObject
.
use objc2::ClassType;
use objc2::runtime::NSObject;
let obj = NSObject::new();
assert_eq!(obj.class(), NSObject::class());
Sourcepub unsafe fn get_ivar<T>(&self, name: &str) -> &Twhere
T: Encode,
👎Deprecated: this is difficult to use correctly, use Ivar::load
instead.Available on crate feature NSAccessibilityConstants
only.
pub unsafe fn get_ivar<T>(&self, name: &str) -> &Twhere
T: Encode,
Ivar::load
instead.NSAccessibilityConstants
only.Use Ivar::load
instead.
§Safety
The object must have an instance variable with the given name, and it
must be of type T
.
See Ivar::load_ptr
for details surrounding this.
Sourcepub fn downcast_ref<T>(&self) -> Option<&T>where
T: DowncastTarget,
Available on crate feature NSAccessibilityConstants
only.
pub fn downcast_ref<T>(&self) -> Option<&T>where
T: DowncastTarget,
NSAccessibilityConstants
only.Attempt to downcast the object to a class of type T
.
This is the reference-variant. Use Retained::downcast
if you want
to convert a retained object to another type.
§Mutable classes
Some classes have immutable and mutable variants, such as NSString
and NSMutableString
.
When some Objective-C API signature says it gives you an immutable class, it generally expects you to not mutate that, even though it may technically be mutable “under the hood”.
So using this method to convert a NSString
to a NSMutableString
,
while not unsound, is generally frowned upon unless you created the
string yourself, or the API explicitly documents the string to be
mutable.
See Apple’s documentation on mutability and on
isKindOfClass:
for more details.
§Generic classes
Objective-C generics are called “lightweight generics”, and that’s because they aren’t exposed in the runtime. This makes it impossible to safely downcast to generic collections, so this is disallowed by this method.
You can, however, safely downcast to generic collections where all the
type-parameters are AnyObject
.
§Panics
This works internally by calling isKindOfClass:
. That means that the
object must have the instance method of that name, and an exception
will be thrown (if CoreFoundation is linked) or the process will abort
if that is not the case. In the vast majority of cases, you don’t need
to worry about this, since both root objects NSObject
and
NSProxy
implement this method.
§Examples
Cast an NSString
back and forth from NSObject
.
use objc2::rc::Retained;
use objc2_foundation::{NSObject, NSString};
let obj: Retained<NSObject> = NSString::new().into_super();
let string = obj.downcast_ref::<NSString>().unwrap();
// Or with `downcast`, if we do not need the object afterwards
let string = obj.downcast::<NSString>().unwrap();
Try (and fail) to cast an NSObject
to an NSString
.
use objc2_foundation::{NSObject, NSString};
let obj = NSObject::new();
assert!(obj.downcast_ref::<NSString>().is_none());
Try to cast to an array of strings.
use objc2_foundation::{NSArray, NSObject, NSString};
let arr = NSArray::from_retained_slice(&[NSObject::new()]);
// This is invalid and doesn't type check.
let arr = arr.downcast_ref::<NSArray<NSString>>();
This fails to compile, since it would require enumerating over the array to ensure that each element is of the desired type, which is a performance pitfall.
Downcast when processing each element instead.
use objc2_foundation::{NSArray, NSObject, NSString};
let arr = NSArray::from_retained_slice(&[NSObject::new()]);
for elem in arr {
if let Some(data) = elem.downcast_ref::<NSString>() {
// handle `data`
}
}
Trait Implementations§
Source§impl AsRef<AnyObject> for NSWorkspace
impl AsRef<AnyObject> for NSWorkspace
Source§impl AsRef<NSObject> for NSWorkspace
impl AsRef<NSObject> for NSWorkspace
Source§impl AsRef<NSWorkspace> for NSWorkspace
impl AsRef<NSWorkspace> for NSWorkspace
Source§impl Borrow<AnyObject> for NSWorkspace
impl Borrow<AnyObject> for NSWorkspace
Source§impl Borrow<NSObject> for NSWorkspace
impl Borrow<NSObject> for NSWorkspace
Source§impl ClassType for NSWorkspace
impl ClassType for NSWorkspace
Source§const NAME: &'static str = "NSWorkspace"
const NAME: &'static str = "NSWorkspace"
Source§type ThreadKind = <<NSWorkspace as ClassType>::Super as ClassType>::ThreadKind
type ThreadKind = <<NSWorkspace as ClassType>::Super as ClassType>::ThreadKind
Source§impl Debug for NSWorkspace
impl Debug for NSWorkspace
Source§impl Deref for NSWorkspace
impl Deref for NSWorkspace
Source§impl Hash for NSWorkspace
impl Hash for NSWorkspace
Source§impl Message for NSWorkspace
impl Message for NSWorkspace
Source§impl NSObjectProtocol for NSWorkspace
impl NSObjectProtocol for NSWorkspace
Source§fn isEqual(&self, other: Option<&AnyObject>) -> bool
fn isEqual(&self, other: Option<&AnyObject>) -> bool
Source§fn hash(&self) -> usize
fn hash(&self) -> usize
Source§fn isKindOfClass(&self, cls: &AnyClass) -> bool
fn isKindOfClass(&self, cls: &AnyClass) -> bool
Source§fn is_kind_of<T>(&self) -> bool
fn is_kind_of<T>(&self) -> bool
isKindOfClass
directly, or cast your objects with AnyObject::downcast_ref