Making "Open With" work correctly!

Hello, Zaftigers. I got an interesting bug report from the field, and I’m a little surprised I never thought of it. There appear to be a few separate but related issues.

I have an application that reads audio files - specifically, WAV, AIFF and MP3 files.

On both Mac and PC you can right click a file and then use “Open With…” to select the application that you actually open the file with.

  1. On the Mac, at least, my application does not come up in the list of applications that will open MP3s.

How do I add my application to the “Open As…” menu for MP3, WAV, etc files?

  1. On the Mac, when I drag an MP3/etc over my application’s file in the Finder, it does NOT light up. (Drag and drop into the running application runs and with great slickness, M-x praise-jules!) How can I make it so that I can drag audio files over my applications file and drop them to open the application with those files?

  2. I can force the program to “Open With…” an MP3. I was not at all surprised to discover that, however, the file that was “opened” doesn’t actually open up in my program, because I don’t have any idea how to detect if this has happened. I tried a few experiments, like looking at juce::JUCEApplication::getCommandLineParameters() (which was empty), but found nothing.

How do I detect the Open With… command going off?

I tried to search here but unfortunately “Open With…” matches far too much. Any ideas?

If you force a certain type of document to open up your application, after the app has initialised it will call JUCEApplication::anotherInstanceStarted (const String &commandLine). The commandLine argument will be the full path name of the clicked file, quoted. You can then use this String to ‘open’ the document within your application.

And in terms of question 1, this thread might help you:

Kick ass! I’m going to try this this very instant… and yes, this does indeed happen. I’ll need to experiment some more to figure out when this is called at startup, etc, but question 3 appears to be decisively solved. Thanks!

That solves 3. Any takers on 1 and 2? UPDATE: there seems to be a solution for 1, thanks again! So we’re down to 2, but now I need to look and see if 1 and 3 imply a solution to 2.

Note to Jules: the documentation for JUCEApplication::anotherInstanceStarted should probably mention 3. Perhaps even JUCEApplication’s docs should mention 1.

Wow, I hadn’t opened the Introjucer in quite a while (I almost always run it from the command line) - very nice looking these days!

Another Jules suggestion - you might want to add into the roll-over help for the “Document File Extensions” in the Introjucer a note as to whether these file extensions are case-sensitive or insensitive. My theory is that they’re case-insensitive and I’m about to find out :smiley: but it never hurts to explicate things.

I hadn’t even considered the functionality of question 2 - it’s not usually part of my workflow of opening documents (in all honesty, I didn’t know it existed!) However I’ve just tested it with my application and it works fine. So I’m guessing if you resolve questions 1 and 3, 2 will be sorted too.

My guess is also that when I solve 1 and 3, I’ll get 2 for free.

Unfortunately, I so far have not gotten 1 to work on the Mac (the PC seems different but fairly easy).

I set my Document file extensions to be mp3, aiff, wav, mp4, aif but no joy there. I’m going to add MP3, AIFF, AIF, MP4 and see if this helps BUT the files I’m testing with seem to have lower case extensions so I doubt this will help.

I can think of several causes. One is that I have two copies of my program on my system - the “release” one and my “tip” version and the OS recognizes this. Another is that I somehow need to refresh the assignments that were already created.

Work continues, I’ll report back here!

EDIT: as expected, adding the upper case files did not work, and neither did deleting all other copies of the program. My next step is to build a release version (these were all debug version) and restart this machine to see what happens.

So no joy yet.

I did try trashing all old copies of the program and rebooting the machine; I also tried putting a . in front of the file extensions (again, the roll-over help for that field should tell you whether or not you should put a . in front of it). However, my program is still not coming up as a Recommended Application for .mp3 or .wav files.

Any thoughts as usual appreciated!

I’ve never really understood how or when OSX decides to associate a file type with an app… There may be info out there somewhere that describes the process but I’ve never found it.

Does this help?

in the plist you can do something like that

<key>CFBundleDocumentTypes</key> <array> <dict> <key>CFBundleTypeExtensions</key> <array> <string>ext</string> </array> <key>CFBundleTypeIconFile</key> <string>Icon</string> <key>CFBundleTypeName</key> <string>My filetype</string> <key>CFBundleTypeOSTypes</key> <array> <string>EXT_</string> </array> <key>CFBundleTypeRole</key> <string>Editor</string> </dict> </array>

Hope this helps

I just tried it out myself by simply adding mp3 (no . ) in the relevant field in introjucer, building the app, and it has straight away appeared in the ‘Open with…’ list for mp3 files. I’m not sure why it isn’t working for you sorry!

Well, there’s lot of information here for me now!

I had looked into “how this works”. Several of these references are promising.

Interesting in particular that someone else is getting good results: might I ask you if you created a new app for this, or if this was an app that had been on your machine before? (I might try creating a new trivial app and comparing results).

I’ll report back when I get further results!

Thanks as always. If any of you are in Berlin, Glasgow, Amsterdam or New York City, I’d love to buy you a drink in the next few weeks… :smiley: (It’s a travelling summer…)

Yes I created a brand new project/app to get these results. I think I have previously got it working with an existing app, though I seem to remember having to tinker with the .plist file to get it working properly.

First update - I created a brand-new project and app, set the file types, built it, and ran it the first time from the Finder on OS/X.

This did not result in it being a Recommended Application for mp3 or wav either. :frowning:

More results tomorrow, I need to attend to other things for a while.

One quick question for millenliam: could you post your Info.plist here from your working toy project?

Mine looks like:

<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "">

Got it!

It’s an issue with how Juce prepares the plist. There are multiple CFBundleTypeExtensions entries in the plist - only the last one is accepted.

So it will only accept the LAST filetype you list. :smiley:

This explains why millenliam’s test worked - he only had one filetype. I had a list of file types - I didn’t check the last file type until now.

Here’s what Juce is generating:

<dict> <key>CFBundleTypeExtensions</key> <array> <string>wav</string> </array> <key>CFBundleTypeName</key> <string>wav</string> <key>CFBundleTypeRole</key> <string>Editor</string> <key>NSPersistentStoreTypeKey</key> <string>XML</string> <key>CFBundleTypeExtensions</key> <array> <string>mp3</string> </array> <key>CFBundleTypeExtensions</key> <array> <string>aif</string> </array>

and here’s the edit that worked for me.

<key>CFBundleTypeExtensions</key> <array> <string>wav</string> <string>aif</string> <string>mp3</string> </array>

Note that it doesn’t seem to care about CFBundleTypeName - but I’m still looking into this…

EDIT: This appears to be a plist that demonstrates correct use of multiple types. I don’t think it’d be too hard to tweak the Introjucer to do the right thing…!

I just discovered this problem but you beat me to posting it! Thanks for the .plist solution - I’m sure that will come in handy at some point.

Great minds think alike!

refreshing beverage ----> millenliam

Ah! Great detective work chaps, I can easily fix that in the plist generation, thanks!