Function

LSCopyApplicationURLsForURL(_:_:)

Locates all known applications suitable for opening an item designated by the specified URL.

Declaration

func LSCopyApplicationURLsForURL(_ inURL: CFURL, _ inRoleMask: LSRolesMask) -> Unmanaged<CFArray>?

Parameters

inURL

A Core Foundation URL reference designating the item for which all suitable applications are requested. See CFURL for a description of the CFURLRef data type.

inRolesMask

A bit mask specifying the applications’ role or roles with respect to the designated item. See LSRolesMask for a description of this mask. This parameter applies only to URLs with a scheme component of file, and is ignored for all other schemes. If the role is unimportant, pass kLSRolesAll.

Return Value

An array of Core Foundation URL references, one for each application that can open the designated item with at least one of the specified roles. You are responsible for releasing the array object. If no suitable applications are found in the Launch Services database, the function will return NULL.

In macOS 10.15 and later, the returned array is sorted with the first element containing the best available application for opening the specified URL. Prior to macOS 10.15, the order of elements in the array was undefined.

Discussion

If the item URL’s scheme is file (designating either a file or a directory), the selection of suitable applications is based on the designated item’s filename extension, file type, and creator signature, along with the role specified by the inRolesMask parameter. Otherwise, the selection is based on the URL scheme (such as http, ftp, or mailto).

Version Notes

Thread-safe since macOS 10.3.

See Also

Locating an Application

func LSGetApplicationForItem(UnsafePointer<FSRef>!, LSRolesMask, UnsafeMutablePointer<FSRef>!, UnsafeMutablePointer<Unmanaged<CFURL>?>!) -> OSStatus

Locates the preferred application for opening an item designated by file-system reference.

Deprecated
func LSGetApplicationForInfo(OSType, OSType, CFString!, LSRolesMask, UnsafeMutablePointer<FSRef>!, UnsafeMutablePointer<Unmanaged<CFURL>?>!) -> OSStatus

Locates the preferred application for opening items with a specified file type, creator signature, filename extension, or any combination of these characteristics.

Deprecated
func LSCopyApplicationForMIMEType(CFString!, LSRolesMask, UnsafeMutablePointer<Unmanaged<CFURL>?>!) -> OSStatus

Locates the preferred application for opening items with a specified MIME type.

Deprecated
func LSCanRefAcceptItem(UnsafePointer<FSRef>!, UnsafePointer<FSRef>!, LSRolesMask, LSAcceptanceFlags, UnsafeMutablePointer<DarwinBoolean>!) -> OSStatus

Tests whether an application can accept (open) an item designated by file-system reference.

Deprecated
func LSCopyApplicationURLsForBundleIdentifier(CFString, UnsafeMutablePointer<Unmanaged<CFError>?>?) -> Unmanaged<CFArray>?

Locates all URLs for applications that correspond to the specified bundle identifier.

func LSFindApplicationForInfo(OSType, CFString!, CFString!, UnsafeMutablePointer<FSRef>!, UnsafeMutablePointer<Unmanaged<CFURL>?>!) -> OSStatus

Locates an application with a specified creator signature, bundle ID, filename, or any combination of these characteristics.

Deprecated