Although Tonyβs information is correct, itβs also explained here - (dragging and dropping MyApp.app into Applications will be automatically registered using launch services using information from Info.plist xml files and installation files), he does not fully answer the question about file associations.
If people follow these instructions, they will open their application, but no file will open.
[...] make sure the system associates a specific file type with my recently installed application
The file combination is slightly different on the Mac compared to other platforms. Most platforms, when *.foo registered with myapp , when MyFile.foo pressed MyFile.foo , it sends something line by line:
/path/to/myapp MyFile.foo
And although you can use this technique on the command line on a Mac with success, it just wonβt work through the Finder , and it wonβt work with a double click on the corresponding file on the desktop.
Answered and answered here:
fooobar.com/questions/851936 / ...
Some argue that this approach is advantageous compared to the conservative workflow in main() , because it "opens only one instance of the application." Regardless of the reasons underlying this solution, this further complicates matters from a C ++ perspective.
- A 108 page PDF is available here (warning, this is marked as a βlegacyβ, a link may occur)
- Related documentation from the Apple Developer Portal is available here .
- The Qt approach is documented here .
From qt.io:
When a user double-clicks a file in Finder, Finder sends an Apple event to the application associated with the file and asks him to open the file. If the application is not running, it starts and then the request is executed. The advantage of this approach is that there is only one instance of the application.
On Windows, this is usually done by running the application and passing the file name as a command line argument. Examining many files leads to the launch of many instances of the same application. (The QtSingleApplication component, available as a Qt solution, solves this problem.)
Qt 3 does not provide abstractions for handling Apple events, but they can be added to the application using the Mac Carbon API. Suppose we have an application called XpmViewer that displays XPM files (X11 image format). The following window class declaration: [code snippet removed]
(BOOL)application:(NSApplication *)theApplication openFile:(NSString *)filename
Handling a Mac OS X File Open Event BEFORE STARTING C ++ main () Runs AEInstallEventHandler Does Not Start When It Starts