What does MacOS actually do when open a file?
Solution 1:
LaunchServices
macOS includes Launch Services. This code is responsible for launching applications and providing those applications with the details of files to open or print:
Launch Services is an API that enables a running application to open other applications or their document files or URLs (uniform resource locators) 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 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
AEOpenDocuments
To open files, graphical applications on macOS are sent AppleEvents of type odoc
:
Event that provides an application with a list of documents to open. Sent, for example, when a selects one or more documents for your application in the Finder and double-clicks them.
The launched application's arguments do not include the paths of the files to open.