How to associate a file type with a MacOS X App without launching it first?

I would like to associate the latest installed version of my Mac OS X application with a specific file type. A little experimentation shows that the info.plist file is apparently read and interpreted by the operating system when the application starts, and not when you drag the application package onto the disk. Apple's runtime documentation does not talk about this topic.

Is there a way using a simple .dmg image as installation media to make sure that the system associates this type of file with my recently installed application without having to run it ? p>

EIDT: I have to clarify that I want this to be done automatically during installation (I don't want my users to have to do this themselves).

Thanks!

+6
installation info.plist macos file-association
source share
3 answers

When the user drags the application into the Applications folder, the system should automatically register it using the Start Services. See Registering Applications in the Service Launch Guide.

+6
source share

You can do this by typing apple-I in the file with which you want to link the application, use the small box called "Open with ..." and select your application. You can check the small box below "Change all ..." to make changes for all similar files.

+1
source share

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

+1
source share

All Articles