When the wrong copy/version of the right app opens a document

I seem to end up with lots of previous versions of the apps I develop, and every once in a while they get to confuse macOS.

When you double-click on a document to open it, LaunchServices checks what type of document it is, in terms of its UTI, then looks up the default app for opening that document type. Let’s say I want to open a PDF file, which has a UTI of com.adobe.pdf. LaunchServices recognises that, and looks up which app opens that type by default.

In my case, it’s Podofyllin, of course. But which version and copy should it open? I’ve got each and every version going back to 1.0b1, and in some cases more than one copy. Unless you’ve set any different, LaunchServices should normally open the most recent version in your Applications folder, which usually coincides with that in the Dock, if it’s installed there.

When the wrong app is opened, it’s simple to fix. Select the document, Get Info, and change the Open with: setting to the app that you want. If you want this to apply to all docs of that UTI, then click on the Change All… button.

wrongapp00

But what should you do when LaunchServices keeps opening the wrong version or copy of the right app, rather than the one that’s installed in your Dock and your Applications folder?

It can help to discover which copy of the app LaunchServices is opening. Double-click on one of its documents, and Control-click on the app’s icon in the Dock. Towards the bottom of the menu, you’ll see the item Options, in which you can Show in Finder.

wrongapp01

This opens a Finder window on the copy of the app which LaunchServices currently uses to open documents with this UTI. That may come as a surprise, as the copy it’s opening may be one which you didn’t know about. In my case, it was a debug build of Podofyllin rather than the release version.

You could of course keep trashing those unwanted copies of the app until finally LaunchServices opens the right one. If you’ve only got a couple of copies, and can get rid of them, this might be a good choice, but it didn’t help me much: LaunchServices decided to find and use the very first version of Podofyllin, and there was another couple of dozen to go before it might reach the right one unaided.

Before going any further, check that the version installed in your main Applications folder (or wherever it should be) is the one that you want LaunchServices to open, and, if it’s installed there, the app in the Dock is one and the same. Then return to the Finder’s Get Info dialog, and open the list of apps which could open that document in the Open with: item.

wrongapp02

In my case, that list isn’t very helpful, and of course it doesn’t tell me which copy of any version it means. So go to the foot of that menu, and select Other… to bring up an Open File dialog, where you select the copy of the app which you want to open those documents with.

wrongapp03

Click on Open and verify that this is the right copy, via the Dock.

Now that is set, click on the Change All… button in the Get Info dialog’s Open with: section. Now you should find LaunchServices opening double-clicked documents using the right app, the right version, and the right copy at last.

LaunchServices often doesn’t cope very well with many and various versions of any given app. The next time that I built a debug version of the next release of Podofyllin, LaunchServices decided to use that as the default for opening PDF files, rather than the newer notarized version installed in Applications. If you need to keep previous versions around, tuck them away in compressed archives if you can. If you need to run them at a moment’s notice and have to leave them uncompressed, ensuring that non-current versions have a different name can make life simpler.

Postscript

Jeff Johnson @lapcatsoftware reports similar problems, in that he found LaunchServices switching to use a new app archive he had made in Xcode. In my case, things are even stranger, because I have an app archive containing the notarized release version of Podofyllin, but LaunchServices keeps going back to the last debug build before that!

He points out that you can use the undocumented command tool lsregister to fix that, in a command such as

/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -R -f -u pathname

where pathname is to the unwanted version of the app. This should dissociate that version with LaunchServices. You could also use a similar command without the -u option to register your preferred copy of the app.