| Framework | ApplicationServices/ApplicationServices.h |
| Companion guide | |
| Declared in | LSInfo.h LSOpen.h |
Mac OS X Launch Services is an API that enables a running application to open other applications or their document files in a way similar to the Finder or the Dock. Using Launch Services, an application can perform such tasks as:
Open (launch or activate) another application
Open a document or a URL (uniform resource locator) in another application
Identify the preferred application for opening a given document or URL
Register information about the kinds of document files and URLs an application is capable of opening
Obtain appropriate information for displaying a file or URL on the screen, such as its icon, display name, and kind string
Maintain and update the contents of the Recent Items menu
Although most of these services are normally performed by the Finder, other applications may also find them useful for purposes such as opening email attachments, following URLs embedded in a document, running helper applications, or opening embedded document components that were created by another application or require it for viewing or editing.
Many of Launch Services’ capabilities were formerly provided by the Desktop Manager. With the advent of Mac OS X application bundles, however, the Desktop Manager has lost its usefulness, since it is not knowledgeable about bundled applications and simply ignores them. Similarly, Launch Services’ facilities for dealing with URLs were formerly implemented through the Internet Config API. Launch Services replaces and supersedes the Desktop Manager and Internet Config with a new API providing similar functionality, but designed to operate properly in the Mac OS X environment.
Launch Services was created specifically to avoid the common need for applications to ask the Finder to open an application, document, or URL for them. In the past, opening such items in a way similar to the Finder required knowledge of several APIs, including the Desktop Manager, File Manager, Translation Manager, Internet Config, Process Manager, and Apple Event Manager. The Finder also had implicit knowledge of the desktop database and other information not available elsewhere for determining the correct application with which to open a given document.
Launch Services removes this specialized knowledge from the Finder and isolates it in a single, straightforward API available to any application. The Mac OS X Finder itself uses Launch Services to open applications, documents, and URLs at the user’s request. Since the Finder does no additional processing beyond calling Launch Services, any client using Launch Services for these purposes is guaranteed to behave identically to the Finder itself.
Before reading this document, you should be familiar with the related document, Launch Services Programming Guide, which presents a conceptual overview of Launch Services and its operations.
This section describes the functions defined in the Launch Services API.
The functions described in this section locate the preferred application for opening a given item or family of items or the application matching a given set of defining characteristics, or test whether an application can open a designated item.
LSGetApplicationForItem
LSGetApplicationForURL
LSGetApplicationForInfo
LSCopyApplicationForMIMEType
LSCopyApplicationURLsForURL
LSCanRefAcceptItem
LSCanURLAcceptURL
LSFindApplicationForInfo
The functions described in this section open a designated item or collection of items, or launch or activate a designated application.
LSOpenApplication
LSOpenItemsWithRole
LSOpenURLsWithRole
LSOpenFSRef
LSOpenFromRefSpec
LSOpenCFURLRef
LSOpenFromURLSpec
The functions described in this section obtain requested information about an item.
LSCopyItemInfoForRef
LSCopyItemInfoForURL
LSCopyDisplayNameForRef
LSCopyDisplayNameForURL
LSCopyKindStringForRef
LSCopyKindStringForURL
LSCopyKindStringForTypeInfo
LSCopyKindStringForMIMEType
LSCopyItemAttribute
LSCopyItemAttributes
The functions described in this section obtain information about an item’s filename extension, or control whether the extension should be hidden or shown on the screen.
The functions described in this section register an application in the Launch Services database.
The functions described in this section get and set application bundle identifiers for handlers of specified content types and URL schemes.
LSCopyAllRoleHandlersForContentType
LSCopyDefaultRoleHandlerForContentType
LSSetDefaultRoleHandlerForContentType
LSGetHandlerOptionsForContentType
LSSetHandlerOptionsForContentType
LSCopyAllHandlersForURLScheme
LSCopyDefaultHandlerForURLScheme
LSSetDefaultHandlerForURLScheme
The functions described in this section are no longer used.
Tests whether an application can accept (open) an item designated by file-system reference.
OSStatus LSCanRefAcceptItem ( const FSRef *inItemFSRef, const FSRef *inTargetRef, LSRolesMask inRoleMask, LSAcceptanceFlags inFlags, Boolean *outAcceptsItem );
A pointer to a file-system reference designating the source item (the item to test for acceptance by the target application); see the File Manager Reference in the Carbon File Management Documentation for a description of the FSRef data type.
A pointer to a file-system reference designating the target application; see the File Manager Reference in the Carbon File Management Documentation for a description of the FSRef data type.
A bit mask specifying the target application’s desired role or roles with respect to the source item; see “Roles Mask” for a description of this mask. If the role is unimportant, pass kLSRolesAll.
Flags specifying behavior to observe during the acceptance test; see “Acceptance Flags” for a description of these flags.
A pointer to a Boolean value that, on return, will indicate whether the target application can accept the source item with at least one of the specified roles.
A result code; see “Launch Services Result Codes.”
Thread-safe since Mac OS version 10.2.
LSInfo.h
Tests whether an application can accept (open) an item designated by URL.
OSStatus LSCanURLAcceptURL ( CFURLRef inItemURL, CFURLRef inTargetURL, LSRolesMask inRoleMask, LSAcceptanceFlags inFlags, Boolean *outAcceptsItem );
A Core Foundation URL reference designating the source item (the item to test for acceptance by the target application); see the CFURL Reference in the Core Foundation Reference Documentation for a description of the CFURLRef data type.
A Core Foundation URL reference designating the target application; see the CFURL Reference in the Core Foundation Reference Documentation for a description of the CFURLRef data type. The URL must have scheme file and contain a valid path to an application file or application bundle.
A bit mask specifying the target application’s desired role or roles with respect to the source item; see “Roles Mask” 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.
Flags specifying behavior to observe during the acceptance test; see “Acceptance Flags” for a description of these flags.
A pointer to a Boolean value that, on return, will indicate whether the target application can accept the source item with at least one of the specified roles.
A result code; see “Launch Services Result Codes.”
If the item URL’s scheme is file (designating either a file or a directory), the acceptance test is based on the designated item’s filename extension, file type, and creator signature, along with the role specified by the inRolesMask parameter; otherwise, it is based on the URL scheme (such as http, ftp, or mailto).
Thread-safe since Mac OS version 10.2.
LSInfo.hReturns an array of application bundle identifiers for applications capable of handling the specified URL scheme.
CFArrayRef LSCopyAllHandlersForURLScheme ( CFStringRef inURLScheme );
The URL scheme for which the application bundle identifiers are to be returned.
An array containing the application bundle identifiers for applications capable of handling the URL scheme specified by inURLScheme, or NULL if no handlers are available.
This function returns all of the application bundle identifiers that are capable of handling the specified URL scheme.
URL handling capability is determined according to the value of the CFBundleURLTypes key in an application’s Info.plist. For information on the CFBundleURLTypes key, see the section “CFBundleURLTypes” in Mac OS X Runtime Configuration Guidelines.
Thread-safe since Mac OS X v10.4.
LSInfo.hReturns an array of application bundle identifiers for applications capable of handling a specified content type with the specified roles.
CFArrayRef LSCopyAllRoleHandlersForContentType ( CFStringRef inContentType, LSRolesMask inRole );
The content type. The content type is a uniform type identifier (UTI).
The role. Pass kLSRolesAll if any role is acceptable. For additional possible values, see “Roles Mask.”
The application bundle identifiers for applications capable of handling the specified content type in the specified roles, or NULL if no handlers are available.
This function returns all of the application bundle identifiers that are capable of handling the specified content type in the specified roles.
The CFBundleDocumentTypes key in an application’s Info.plist can be used to set an application’s content handling capabilities. The LSItemContentTypes key is particularly useful because it supports the use of UTIs in document claims. For information on the CFBundleDocumentTypes key, see the section “CFBundleDocumentTypes” in Mac OS X Runtime Configuration Guidelines.
Thread-safe since Mac OS X v10.4.
LSInfo.h
Locates the preferred application for opening items with a specified MIME type.
OSStatus LSCopyApplicationForMIMEType ( CFStringRef inMIMEType, LSRolesMask inRoleMask, CFURLRef *outAppURL );
A Core Foundation string object specifying the MIME type to consider; see the CFString Reference in the Core Foundation Reference Documentation for a description of the CFStringRef data type. Comparison of MIME types is case-insensitive.
A bit mask specifying the application’s desired role or roles with respect to items with the specified MIME type; see “Roles Mask” for a description of this mask. If the role is unimportant, pass kLSRolesAll.
A pointer to a Core Foundation URL reference that, on return, will identify the preferred application for items with the specified MIME type; see the CFURL Reference in the Core Foundation Reference Documentation for a description of the CFURLRef data type. You are responsible for releasing the URL reference object.
A result code; see “Launch Services Result Codes.” If no application suitable for opening items with the specified MIME type is found in the Launch Services database, the function will return the result code kLSApplicationNotFoundErr.
Thread-safe since Mac OS version 10.2.
LSInfo.hLocates all known applications suitable for opening an item designated by URL.
CFArrayRef LSCopyApplicationURLsForURL ( CFURLRef inURL, LSRolesMask inRoleMask );
A Core Foundation URL reference designating the item for which all suitable applications are requested; see the CFURL Reference in the Core Foundation Reference Documentation for a description of the CFURLRef data type.
A bit mask specifying the applications’ desired role or roles with respect to the designated item; see “Roles Mask” 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.
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
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, it is based on the URL scheme (such as http, ftp, or mailto).
Thread-safe since Mac OS version 10.3.
LSInfo.hReturns the application bundle identifier of the user’s preferred default handler for the specified URL scheme.
CFStringRef LSCopyDefaultHandlerForURLScheme ( CFStringRef inURLScheme );
The URL scheme for which the application bundle identifier is to be returned.
The application bundle identifier of the specified URL scheme.
This function returns the user’s currently preferred default handler for the specified URL scheme.
URL handling capability is determined according to the value of the CFBundleURLTypes key in an application’s Info.plist. For information on the CFBundleURLTypes key, see the section “CFBundleURLTypes” in Mac OS X Runtime Configuration Guidelines.
Thread-safe since Mac OS X v10.4.
LSInfo.hReturns the application bundle identifier of the user’s preferred default handler for the specified content type with the specified role.
CFStringRef LSCopyDefaultRoleHandlerForContentType ( CFStringRef inContentType, LSRolesMask inRole );
The content type. The content type is a uniform type identifier (UTI).
The role. Pass kLSRolesAll if any role is acceptable. For additional possible values, see “Roles Mask.”
The application bundle identifier of the default handler for the specified content type in the specified roles, or NULL if no handler is available.
This function returns the user’s currently preferred default handler for the specified content type. Say, for example, that LSSetDefaultRoleHandlerForContentType has been used to set “com.Apple.TextEdit” for the “public.xml” content type. When a file whose content type is “public.xml” is double-clicked, TextEdit will be launched to open the file. If you call LSCopyDefaultRoleHandlerForContentType
(CFSTR("public.xml"), kLSRolesAll), the string com.apple.TextEdit is returned.
The CFBundleDocumentTypes key in an application’s Info.plist can be used to set an application’s content handling capabilities. The LSItemContentTypes key is particularly useful because it supports the use of UTIs in document claims. For information on the CFBundleDocumentTypes key, see the section “CFBundleDocumentTypes” in Mac OS X Runtime Configuration Guidelines.
Thread-safe since Mac OS X v10.4.
LSInfo.h
Obtains the display name for an item designated by file-system reference.
OSStatus LSCopyDisplayNameForRef ( const FSRef *inRef, CFStringRef *outDisplayName );
A pointer to a file-system reference designating the item whose display name is requested; see the File Manager Reference in the Carbon File Management Documentation for a description of the FSRef data type.
A pointer to a Core Foundation string object that, on return, will contain the item’s display name; see the CFString Reference in the Core Foundation Reference Documentation for a description of the CFStringRef data type. You are responsible for releasing this object.
A result code; see “Launch Services Result Codes.”
The item’s display name is returned in the form in which it will appear on the user’s screen; it may be localized (for applications and folders), and it excludes the filename extension if the extension is set to be hidden and the Finder preference to always show extensions is not enabled.
Thread-safe since Mac OS version 10.2.
LSInfo.h
Obtains the display name for an item designated by URL.
OSStatus LSCopyDisplayNameForURL ( CFURLRef inURL, CFStringRef *outDisplayName );
A Core Foundation URL reference designating the item whose display name is requested; see the CFURL Reference in the Core Foundation Reference Documentation for a description of the CFURLRef data type. The URL must have scheme file and contain a valid path to either a file or a directory.
A pointer to a Core Foundation string object that, on return, will contain the item’s display name; see the CFString Reference in the Core Foundation Reference Documentation for a description of the CFStringRef data type. You are responsible for releasing this object.
A result code; see “Launch Services Result Codes.”
The item’s display name is returned in the form in which it will appear on the user’s screen; it may be localized (for applications and folders), and it excludes the filename extension if the extension is set to be hidden and the Finder preference to always show extensions is not enabled.
Thread-safe since Mac OS version 10.2.
LSInfo.hObtains the value of an item’s attribute.
OSStatus LSCopyItemAttribute ( const FSRef *inItem, LSRolesMask inRoles, CFStringRef inAttributeName, CFTypeRef *outValue );
The FSRef of the item to query.
The roles. When obtaining attributes related to document binding (such as kLSItemRoleHandlerDisplayName), at least one of the roles must be provided by the application selected. Pass kLSRolesAll if any role is acceptable.
The name of the attribute to copy. For possible values, see “Item Attribute Constants.”
A pointer to a CFTypeRef. On return, the CFTypeRef is set to the copied attribute value (a CF object), or is NULL if an error occurs. The type of the returned object varies depending on the attribute that is requested.
A result code; see “Launch Services Result Codes.”
Thread-safe since Mac OS X v10.4.
LSInfo.hObtains multiple item attribute values as a dictionary.
OSStatus LSCopyItemAttributes ( const FSRef *inItem, LSRolesMask inRoles, CFArrayRef inAttributeNames, CFDictionaryRef *outValues );
The FSRef of the item to query.
The roles. When obtaining attributes related to document binding (such as kLSItemRoleHandlerDisplayName), at least one of the roles must be provided by the application selected. Pass kLSRolesAll if any role is acceptable.
A CFArrayRef for an array containing the attribute names to copy. For possible values, see “Item Attribute Constants.”
On return, a pointer a CFDictionaryRef for a dictionary whose keys are the attribute names specified by the inAttributeNames parameter and whose values are the attribute’s values. The CFTypeID of each value in the dictionary varies by attribute. See “Item Attribute Constants” for the data type of each value. If the item does not have a specified attribute, the key for the attribute is not in the dictionary.
A result code; see “Launch Services Result Codes.”
Thread-safe since Mac OS X v10.4.
LSInfo.h
Obtains requested information about an item designated by file-system reference.
OSStatus LSCopyItemInfoForRef ( const FSRef *inItemRef, LSRequestedInfo inWhichInfo, LSItemInfoRecord *outItemInfo );
A pointer to a file-system reference designating the item about which information is requested; see the File Manager Reference in the Carbon File Management Documentation for a description of the FSRef data type.
Flags specifying what information to obtain; see “Requested-Information Flags” for a description of these flags.
A pointer to an item-information record that, on return, will contain the requested information; see “LSItemInfoRecord” for a description of this structure.
If you request the item’s filename extension (field extension of the item-information record, requested by flag kLSRequestExtension), you are responsible for releasing the Core Foundation string object in which the extension is returned.
A result code; see “Launch Services Result Codes.”
The information obtained about an item can include its filename extension, file type, creator signature, and various item-information flags (indicating, for example, whether the item is an application, or whether it has a hidden extension); see “Item-Information Flags” for a description of these flags.
Thread-safe since Mac OS version 10.2.
LSInfo.h
Obtains requested information about an item designated by URL.
OSStatus LSCopyItemInfoForURL ( CFURLRef inURL, LSRequestedInfo inWhichInfo, LSItemInfoRecord *outItemInfo );
A Core Foundation URL reference designating the item about which information is requested; see the CFURL Reference in the Core Foundation Reference Documentation for a description of the CFURLRef data type. The URL must have scheme file and contain a valid path to either a file or a directory.
Flags specifying what information to obtain; see “Requested-Information Flags” for a description of these flags.
A pointer to an item-information record that, on return, will contain the requested information; see “LSItemInfoRecord” for a description of this structure.
If you request the item’s filename extension (field extension of the item-information record, requested by flag kLSRequestExtension), you are responsible for releasing the Core Foundation string object in which the extension is returned.
A result code; see “Launch Services Result Codes.”
The information obtained about an item can include its filename extension, file type, creator signature, and various item-information flags (indicating, for example, whether the item is an application, or whether it has a hidden extension); see “Item-Information Flags” for a description of these flags.
Thread-safe since Mac OS version 10.2.
LSInfo.h
Obtains the kind string for a specified MIME type.
OSStatus LSCopyKindStringForMIMEType ( CFStringRef inMIMEType, CFStringRef *outKindString );
A Core Foundation string object specifying the MIME type whose kind string is requested; see the CFString Reference in the Core Foundation Reference Documentation for a description of the CFStringRef data type. Comparison of MIME types is case-insensitive.
A pointer to a Core Foundation string object that, on return, will contain the kind string for the specified MIME type; see the CFString Reference in the Core Foundation Reference Documentation for a description of the CFStringRef data type. You are responsible for releasing this object.
A result code; see “Launch Services Result Codes.”
The kind string (which may be localized) is obtained from the preferred application for opening items of the specified the MIME type, if one is found in the Launch Services database; otherwise, a more generic kind string is chosen.
Thread-safe since Mac OS version 10.2.
LSInfo.h
Obtains the kind string for an item designated by file-system reference.
OSStatus LSCopyKindStringForRef ( const FSRef *inFSRef, CFStringRef *outKindString );
A pointer to a file-system reference designating the item whose kind string is requested; see the File Manager Reference in the Carbon File Management Documentation for a description of the FSRef data type.
A pointer to a Core Foundation string object that, on return, will contain the item’s kind string; see the CFString Reference in the Core Foundation Reference Documentation for a description of the CFStringRef data type. You are responsible for releasing this object.
A result code; see “Launch Services Result Codes.”
The kind string (which may be localized) is obtained from the item’s preferred application, if one is found in the Launch Services database; otherwise, a more generic kind string is chosen. For example, the kind string might be FrameMaker
Document, or just Document if the item is a document for which no application is found.
Thread-safe since Mac OS version 10.2.
LSInfo.h
Obtains a kind string for items with a specified file type, creator signature, filename extension, or any combination of these characteristics.
OSStatus LSCopyKindStringForTypeInfo ( OSType inType, OSType inCreator, CFStringRef inExtension, CFStringRef *outKindString );
The file type to consider. Comparison of file types is case-sensitive. Pass kLSUnknownType if the items’ file type is unimportant.
The creator signature to consider. Comparison of creator signatures is case-sensitive. Pass kLSUnknownCreator if the items’ creator signature is unimportant.
A Core Foundation string object specifying the filename extension to consider; see the CFString Reference in the Core Foundation Reference Documentation for a description of the CFStringRef data type. Comparison of filename extensions is case-insensitive. Pass NULL if the items’ filename extension is unimportant.
A pointer to a Core Foundation string object that, on return, will contain the requested kind string; see the CFString Reference in the Core Foundation Reference Documentation for a description of the CFStringRef data type. You are responsible for releasing this object.
A result code; see “Launch Services Result Codes.”
This function obtains the kind string that most closely describes items having the specified characteristics. It is useful when you want to display the kind string for a document you do not yet have (such as an email attachment).
You can request any combination of one, two, or all three of the characteristics specified by the inType, inCreator, and inExtension parameters; at least one of these characteristics must be supplied. The kind string (which may be localized) is obtained from the preferred application for opening such items, if one is found in the Launch Services database; otherwise, a more generic kind string is chosen. For example, the kind string might be FrameMaker Document, or just Document if no suitable application is found.
Note that since the choice of a preferred application is subject to any document binding preferences the user may have set, the kind string will not necessarily be obtained from the default application that matches the specified creator signature (if any), but may instead be taken from a user-specified application that overrides the default. For example, if the user has specified that files of type 'PDF
' and creator 'ACRO' should be opened in the Preview application rather than in Acrobat, the kind string for this combination of characteristics will be that defined for 'PDF ' files by Preview and not by Acrobat.
Thread-safe since Mac OS version 10.2
LSInfo.h
Obtains the kind string for an item designated by URL.
OSStatus LSCopyKindStringForURL ( CFURLRef inURL, CFStringRef *outKindString );
A Core Foundation URL reference designating the item whose kind string is requested; see the CFURL Reference in the Core Foundation Reference Documentation for a description of the CFURLRef data type.
A pointer to a Core Foundation string object that, on return, will contain the item’s kind string; see the CFString Reference in the Core Foundation Reference Documentation for a description of the CFStringRef data type. You are responsible for releasing this object.
A result code; see “Launch Services Result Codes.”
The kind string (which may be localized) is obtained from the item’s preferred application, if one is found in the Launch Services database; otherwise, a more generic kind string is chosen. For example, the kind string might be FrameMaker
Document, or just Document if the item is a document for which no application is found. If the item URL’s scheme is file (designating either a file or a directory), the selection of the preferred application is based on the designated item’s filename extension, file type, and creator signature; otherwise, it is based on the URL scheme (such as http, ftp, or mailto).
Thread-safe since Mac OS version 10.2.
LSInfo.h
Locates an application with a specified creator signature, bundle ID, filename, or any combination of these characteristics.
OSStatus LSFindApplicationForInfo ( OSType inCreator, CFStringRef inBundleID, CFStringRef inName, FSRef *outAppRef, CFURLRef *outAppURL );
The creator signature to consider. Comparison of creator signatures is case-sensitive. Pass kLSUnknownCreator if the application’s creator signature is unimportant.
A Core Foundation string object specifying the bundle ID to consider; see the CFString Reference in the Core Foundation Reference Documentation for a description of the CFStringRef data type. Comparison of bundle IDs is case-insensitive. Pass NULL if the application’s bundle ID is unimportant.
A Core Foundation string object specifying the filename to consider; see the CFString Reference in the Core Foundation Reference Documentation for a description of the CFStringRef data type. The string must include any extension (such as '.app') that is part of the filename. Comparison of filenames is case-insensitive. Pass NULL if the application’s filename is unimportant.
A pointer to a file-system reference that, on return, will identify the requested application; see the File Manager Reference in the Carbon File Management Documentation for a description of the FSRef data type. Pass NULL if you are not interested in identifying the application in this form; however, this parameter and outAppURL cannot both be NULL.
A pointer to a Core Foundation URL reference that, on return, will identify the requested application; see the CFURL Reference in the Core Foundation Reference Documentation for a description of the CFURLRef data type. Pass NULL if you are not interested in identifying the application in this form; however, this parameter and outAppRef cannot both be NULL.
Despite the absence of the word Copy in its name, this function retains the URL reference object on your behalf; you are responsible for releasing this object.
A result code; see “Launch Services Result Codes.” If no suitable application is found in the Launch Services database, the function will return the result code kLSApplicationNotFoundErr.
You can request any combination of one, two, or all three of the characteristics specified by the inCreator, inBundleID, and inName parameters; at least one of these characteristics must be supplied. If more than one application is found matching the specified characteristics, Launch Services chooses one in the same manner as when locating the preferred application for opening an item.
Thread-safe since Mac OS version 10.2.
LSInfo.h
Locates the preferred application for opening items with a specified file type, creator signature, filename extension, or any combination of these characteristics.
OSStatus LSGetApplicationForInfo ( OSType inType, OSType inCreator, CFStringRef inExtension, LSRolesMask inRoleMask, FSRef *outAppRef, CFURLRef *outAppURL );
The file type to consider. Comparison of file types is case-sensitive. Pass kLSUnknownType if the items’ file type is unimportant.
The creator signature to consider. Comparison of creator signatures is case-sensitive. Pass kLSUnknownCreator if the items’ creator signature is unimportant.
A Core Foundation string object specifying the filename extension to consider; see the CFString Reference in the Core Foundation Reference Documentation for a description of the CFStringRef data type. Comparison of filename extensions is case-insensitive. Pass NULL if the items’ filename extension is unimportant.
A bit mask specifying the application’s desired role or roles with respect to items with the specified characteristics; see “Roles Mask” for a description of this mask. If the role is unimportant, pass kLSRolesAll.
A pointer to a file-system reference that, on return, will identify the preferred application for opening items with the specified characteristics; see the File Manager Reference in the Carbon File Management Documentation for a description of the FSRef data type. Pass NULL if you are not interested in identifying the preferred application in this form; however, this parameter and outAppURL cannot both be NULL.
A pointer to a Core Foundation URL reference that, on return, will identify the preferred application for items with the specified characteristics; see the CFURL Reference in the Core Foundation Reference Documentation for a description of the CFURLRef data type. Pass NULL if you are not interested in identifying the preferred application in this form; however, this parameter and outAppRef cannot both be NULL.
Despite the absence of the word Copy in its name, this function retains the URL reference object on your behalf; you are responsible for releasing this object.
A result code; see “Launch Services Result Codes.” If no application suitable for opening items with the specified characteristics is found in the Launch Services database, the function will return the result code kLSApplicationNotFoundErr.
You can request any combination of one, two, or all three of the characteristics specified by the inType, inCreator, and inExtension parameters; at least one of these characteristics must be supplied. Note that since the choice of a preferred application is subject to any document binding preferences the user may have set, the application chosen will not necessarily be the default application that matches the input characteristics, but may instead be a user-specified application that overrides the default.
Thread-safe since Mac OS version 10.2.
LSInfo.h
Locates the preferred application for opening an item designated by file-system reference.
OSStatus LSGetApplicationForItem ( const FSRef *inItemRef, LSRolesMask inRoleMask, FSRef *outAppRef, CFURLRef *outAppURL );
A pointer to a file-system reference designating the item whose preferred application is requested; see the File Manager Reference in the Carbon File Management Documentation for a description of the FSRef data type.
A bit mask specifying the application’s desired role or roles with respect to the designated item; see “Roles Mask” for a description of this mask. If the role is unimportant, pass kLSRolesAll.
A pointer to a file-system reference that, on return, will identify the item’s preferred application; see the File Manager Reference in the Carbon File Management Documentation for a description of the FSRef data type. Pass NULL if you are not interested in identifying the preferred application in this form; however, this parameter and outAppURL cannot both be NULL.
A pointer to a Core Foundation URL reference that, on return, will identify the item’s preferred application; see the CFURL Reference in the Core Foundation Reference Documentation for a description of the CFURLRef data type. Pass NULL if you are not interested in identifying the preferred application in this form; however, this parameter and outAppRef cannot both be NULL.
Despite the absence of the word Copy in its name, this function retains the URL reference object on your behalf; you are responsible for releasing this object.
A result code; see “Launch Services Result Codes.” If no application suitable for opening the item is found in the Launch Services database, the function will return the result code kLSApplicationNotFoundErr.
Thread-safe since Mac OS version 10.2.
LSInfo.h
Locates the preferred application for opening an item designated by URL.
OSStatus LSGetApplicationForURL ( CFURLRef inURL, LSRolesMask inRoleMask, FSRef *outAppRef, CFURLRef *outAppURL );
A Core Foundation URL reference designating the item whose preferred application is requested; see the CFURL Reference in the Core Foundation Reference Documentation for a description of the CFURLRef data type.
A bit mask specifying the application’s desired role or roles with respect to the designated item; see “Roles Mask” 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.
A pointer to a file-system reference that, on return, will identify the item’s preferred application; see the File Manager Reference in the Carbon File Management Documentation for a description of the FSRef data type. Pass NULL if you are not interested in identifying the preferred application in this form; however, this parameter and outAppURL cannot both be NULL.
A pointer to a Core Foundation URL reference that, on return, will identify the item’s preferred application; see the CFURL Reference in the Core Foundation Reference Documentation for a description of the CFURLRef data type. Pass NULL if you are not interested in identifying the preferred application in this form; however, this parameter and outAppRef cannot both be NULL.
Despite the absence of the word Copy in its name, this function retains the URL reference object on your behalf; you are responsible for releasing this object.
A result code; see “Launch Services Result Codes.” If no application suitable for opening the item is found in the Launch Services database, the function will return the result code kLSApplicationNotFoundErr.
If the item URL’s scheme is file (designating either a file or a directory), the selection of the preferred application is based on the designated item’s filename extension, file type, and creator signature, along with the role specified by the inRolesMask parameter; otherwise, it is based on the URL scheme (such as http, ftp, or mailto).
Thread-safe since Mac OS version 10.2.
LSInfo.h
Obtains the starting index of the extension within a filename.
OSStatus LSGetExtensionInfo ( UniCharCount inNameLen, const UniChar inNameBuffer[], UniCharCount *outExtStartIndex );
The number of characters in the filename specified by the inNameBuffer parameter.
The buffer containing the filename’s Unicode characters.
A pointer to a value of type UniCharCount that, on return, will give the starting index of the extension within the filename. If the name does not contain a valid extension (one with no spaces in it), the value on return will be kLSInvalidExtensionIndex.
A result code; see “Launch Services Result Codes.”
The starting index is the number of Unicode characters from the start of the filename buffer to the first character of the extension (not including the period).
Thread-safe since Mac OS version 10.2.
LSInfo.hGets the handler options for the specified content type.
LSHandlerOptions LSGetHandlerOptionsForContentType ( CFStringRef inContentType );
The content type for which the handler options are to be obtained. The content type is a uniform type identifier (UTI).
The handler option that is set for the specified content type. For possible values, see “Handler Option Constants.”
Thread-safe since Mac OS X v10.4.
LSInfo.h
Launches the specified application.
OSStatus LSOpenApplication ( const LSApplicationParameters *appParams, ProcessSerialNumber *outPSN );
A LSApplicationParameters structure specifying the application to launch and its launch parameters. This parameter cannot be NULL.
On input, a pointer to a value of type ProcessSerialNumber that, on return, contains the process serial number (PSN) of the application specified by inAppParams, or NULL if you don’t want to receive the PSN.
A result code; see “Launch Services Result Codes.”
The LSOpenApplication launches one application. This function is an updated alternative to the Process Manager's LaunchApplication function. Launch arguments are specified in the inAppParams argument, which must be supplied. If the application is already running in the current session, it is made the front process (unless the kLSLaunchNewInstance flag is used, which always causes a new process to be created).
If outPSN is not NULL, on return, the structure it points to contains the PSN of the launched (or activated) process. Note that for asynchronous launches, the application may not have finished launching when this function returns.
Thread-safe since Mac OS X v10.4.
LSOpen.h
Opens an item designated by URL, in the default manner in its preferred application.
OSStatus LSOpenCFURLRef ( CFURLRef inURL, CFURLRef *outLaunchedURL );
A Core Foundation URL reference designating the item to open; see the CFURL Reference in the Core Foundation Reference Documentation for a description of the CFURLRef data type.
A pointer to a Core Foundation URL reference that, on return, will identify the application launched. Pass NULL if this information is unimportant.
Despite the absence of the word Copy in its name, this function retains the URL reference object on your behalf; you are responsible for releasing this object.
A result code; see “Launch Services Result Codes.”
The designated item is opened in the default manner, as if it had been opened with the LSOpenFromURLSpec function with a launch specification specifying the launch flag kLSLaunchDefaults: that is, asynchronously, starting the Classic emulation environment if necessary, and with the remaining launch parameters taken from the application’s information property list. For greater control, call LSOpenFromURLSpec directly. See “Launch Flags” for more information about launch flags.
If the item URL’s scheme is file (designating either a file or a directory), the selection of the preferred application is based on the designated item’s filename extension, file type, and creator signature; otherwise, it is based on the URL scheme (such as http, ftp, or mailto). The application is launched or activated, as required, and sent an appropriate Apple event depending on the circumstances:
If the URL’s scheme is file and it designates a document, the document’s preferred application is launched (or activated if it is already running).
If the application claims to accept file URLs, it is sent a 'GURL' (“get URL”) Apple event containing the item’s URL.
If the application does not claim to accept file URLs, it is sent an 'odoc' (“open document”) Apple event identifying the document to open.
If the URL’s scheme is file and it designates an application:
If the application is not already running, it is launched and sent an 'oapp' (“open application”) Apple event.
If the application is already running, it is activated and sent an 'rapp' (“reopen application”) Apple event.
If the URL has a scheme other than file, the scheme’s preferred application is launched (or activated if it is already running) and sent a 'GURL' (“get URL”) Apple event containing the item’s URL.
As of Mac OS X v10.4 and later, LSOpenURLsWithRole is the preferred way of opening a URL.
Thread-safe since Mac OS version 10.2.
LSOpen.h
Opens one or more items designated by file-system reference, in either their preferred applications or a designated application.
OSStatus LSOpenFromRefSpec ( const LSLaunchFSRefSpec *inLaunchSpec, FSRef *outLaunchedRef );
A pointer to a file-based launch specification indicating what to open and how to launch the relevant application or applications; see “LSLaunchFSRefSpec” for a description of this structure.
A pointer to a file-system reference that, on return, will identify the application launched; see the File Manager Reference in the Carbon File Management Documentation for a description of the FSRef data type. Pass NULL if this information is unimportant. If more than one application is launched, the one identified will be the one corresponding to the first item designated in the launch specification.
A result code; see “Launch Services Result Codes.”
This function affords greater control of how items are opened or applications launched than is possible with the LSOpenFSRef function. For instance, you can use it to open multiple items in a single call, in either the same or different applications; open documents for printing rather than for simple viewing or editing; or force a document to open in an application other than its own preferred application.
The launch specification supplied for the inLaunchSpec parameter may designate an application to launch, items to open, or both. The relevant application or applications are launched or activated, as required, and sent an appropriate Apple event depending on the circumstances:
If the launch specification designates both items to open and an application with which to open them, the designated application is used to open all of the items. The application is launched (or activated if it is already running) and sent an 'odoc' (“open document”) Apple event containing the list of items to open; if the items are to be printed, the Apple event is 'pdoc' (“print document”) instead.
Note: When both an application and a list of items are supplied, the designated application is asked to open all of the items, whether or not it claims the ability to do so. Launch Services does not report an error if the application is unable to open one or more of the items; any error processing is the application’s responsibility.
If the launch specification designates items to open but not an application with which to open them, each item is opened in its own preferred application. Each application is launched or activated and sent an 'odoc' or 'pdoc' Apple event, as described for the preceding case. (If two or more of the items have the same preferred application, the application receives a single 'odoc' or 'pdoc' event listing all of the relevant items.)
If the launch specification designates only an application to launch (or if one or more of the items to open are applications):
If the application is not already running, it is launched and sent an 'oapp' (“open application”) Apple event.
If the application is already running, it is activated and sent an 'rapp' (“reopen application”) Apple event.
As of Mac OS X v10.4 and later, LSOpenItemsWithRole is the preferred way of opening items.
Thread-safe since Mac OS version 10.2.
LSOpen.h
Opens one or more items designated by URL, in either their preferred applications or a designated application.
OSStatus LSOpenFromURLSpec ( const LSLaunchURLSpec *inLaunchSpec, CFURLRef *outLaunchedURL );
A pointer to a URL-based launch specification indicating what to open and how to launch the relevant application or applications; see “LSLaunchURLSpec” for a description of this structure.
A pointer to a Core Foundation URL reference that, on return, will identify the application launched; see the CFURL Reference in the Core Foundation Reference Documentation for a description of the CFURLRef data type. Pass NULL if this information is unimportant. If more than one application is launched, the one identified will be the one corresponding to the first item designated in the launch specification.
Despite the absence of the word Copy in its name, this function retains the URL reference object on your behalf; you are responsible for releasing this object.
A result code; see “Launch Services Result Codes.”
This function affords greater control of how items are opened or applications launched than is possible with the LSOpenCFURLRef function. For instance, you can use it to open multiple items in a single call, in either the same or different applications; open documents for printing rather than for simple viewing or editing; or force a document to open in an application other than its own preferred application.
The launch specification supplied for the inLaunchSpec parameter may designate an application to launch, items to open, or both. The relevant application or applications are launched or activated, as required, and sent an appropriate Apple event depending on the circumstances:
If the launch specification designates both items to open and an application with which to open them, the designated application is used to open all of the items. The application is launched (or activated if it is already running) and sent one or more Apple events:
If one or more of the item URLs have scheme file and designate documents to open, and if the application claims to accept file URLs, it is sent a 'GURL' (“get URL”) Apple event for each such URL.
If one or more of the item URLs have scheme file and designate documents to open, and if the application does not claim to accept file URLs, it is sent a single 'odoc' (“open document”) Apple event containing the list of items to open; if the items are to be printed, the Apple event is 'pdoc' (“print document”) instead.
For each item URL with a scheme other than file, the application is sent a 'GURL' (“get URL”) Apple event containing the item’s URL.
Note: When both an application and a list of items are supplied, the designated application is asked to open all of the items, whether or not it claims the ability to do so. Launch Services does not report an error if the application is unable to open one or more of the items; any error processing is the application’s responsibility.
If the launch specification designates items to open but not an application with which to open them, each item is opened in its own preferred application. Each application is launched or activated and sent one or more Apple events, as described for the preceding case. (If two or more of the items have the same preferred application, the application receives a single 'odoc' or 'pdoc' event listing all of the relevant items.)
If the launch specification designates only an application to launch (or if one or more of the items to open are file URLs designating applications):
If the application is not already running, it is launched and sent an 'oapp' (“open application”) Apple event.
If the application is already running, it is activated and sent an 'rapp' (“reopen application”) Apple event.
As of Mac OS X v10.4 and later, LSOpenURLsWithRole is the preferred way of opening URLs.
Thread-safe since Mac OS version 10.2.
LSOpen.h
Opens an item designated by file-system reference, in the default manner in its preferred application.
OSStatus LSOpenFSRef ( const FSRef *inRef, FSRef *outLaunchedRef );
A pointer to a file-system reference designating the item to open; see the File Manager Reference in the Carbon File Management Documentation for a description of the FSRef data type.
A pointer to a file-system reference that, on return, will identify the application launched. Pass NULL if this information is unimportant.
A result code; see “Launch Services Result Codes.”
The designated item is opened in the default manner, as if it had been opened with the LSOpenFromRefSpec function with a launch specification specifying the launch flag kLSLaunchDefaults: that is, asynchronously, starting the Classic emulation environment if necessary, and with the remaining launch parameters taken from the application’s information property list. For greater control, call LSOpenFromRefSpec directly. See “Launch Flags” for more information about launch flags.
The application is launched or activated, as required, and sent an appropriate Apple event depending on the circumstances:
If the item is a document, its preferred application is launched (or activated if it is already running) and sent an 'odoc' (“open document”) Apple event.
If the item is an application that is not already running, it is launched and sent an 'oapp' (“open application”) Apple event.
If the item is an application that is already running, it is activated and sent an 'rapp' (“reopen application”) Apple event.
As of Mac OS X v10.4 and later, LSOpenItemsWithRole is the preferred way of opening an item.
Thread-safe since Mac OS version 10.2.
LSOpen.h
Opens items specified as an array of values of type FSRef with a specified role.
OSStatus LSOpenItemsWithRole ( const FSRef *inItems, CFIndex inItemCount, LSRolesMask inRole, const AEKeyDesc *inAEParam, const LSApplicationParameters *inAppParams, ProcessSerialNumber *outPSNs, CFIndex inMaxPSNCount );
An array of values of type FSRef.
The number of items specified in inItems.
A value of type LSRolesMask specifying one or more roles. If the role doesn’t matter, use kLSRolesAll. For possible values, see “Roles Mask.” If the inAppParams parameter is not NULL, this parameter is ignored.
An AEKeyDesc that is to be attached to the Apple Event(s) generated by Launch Services with the specified AEKeyword. This parameter can be NULL.
An LSApplicationParameters structure specifying the application to launch and its launch parameters, in which case the inRole parameter is ignored. This parameter can be NULL, in which case an application is selected that can handle each input item in at least one of the roles specified by the inRole parameter.
On input, a pointer to a caller-allocated buffer or NULL if you don’t want to receive process serial number (PSN) information. If not NULL on input, on return, the buffer contains at each index the PSN that was used to open the item at the same index of the input item array (inItems).
The maximum number of PSNs that the buffer pointed to by outPSNs can hold.
A result code; see “Launch Services Result Codes.”
This function opens the specified items with the specified role. You can optionally specify the application and launch parameters in the inAppParams parameter. If an application is specified in the inAppParams parameter, the inRole parameter is ignored and the application is launched (if necessary).
Each application (regardless of whether it is launched or already running) receives an 'odoc' Apple Event specifying the items