Fixing swf file association in 10.5

A few years ago I was working on an installation making little flash projector clients to be installed at a children's museum. A few days later I was preparing for a presentation, double-clicked a swf file, and it opened in, surprisingly enough, the kiosk client projector I'd published a few days later. Confused, I quit and launched it again. Same results. What was happening was that the swf would open the projector file and then open the swf in an additional window. Since I was working in Flash, installing applications for museums and kiosks, the problem grew worse and worse as I published more and more .app's. I grew used to having to right-click any swf I wanted to open, select "Open With...", scroll waaaaay down the list of prototype and final applications that I'd published until I got to the Flash Player, make sure I was selecting the correct one (the most recent player), and opening the swf. Double click was completely broken, even if I told OS X to associate all swfs with the player. It would always revert to opening in one of my applications.

This being the Weekend of Fixing All Things That Have Been Bothering Me, I investigated this problem further. It's somewhat moot because now I can publish as an AIR application and it doesn't hijack file associations. But I still have a very, very large collection of applications from previous projects and I'm not about to rewrite them all for AIR. After a very frustrating morning I've finally found a pretty good solution. Not ideal (it requires quite a bit of plist hacking and forcing the OS to rebuild file associations), seems to have broken .app's in my flex bin-debug folders, but I still have app files for every project I've worked on and they no longer register themselves as being able to open swfs. And yes, they do still open the swf bundled in the application.

What turned out to be the problem was that publishing an .app from the Flash IDE generated a property list for the application that included a file association with swf files. I don't know if this was intended or accidental on Macromedia/Adobe's part and I don't know if it's still that way in CS4 (I'll probably test if I have some free time), but the end result is that you won't know what's going to open your swfs when you double click them. I can't really think of a good reason for this file association because the unix executable that runs when you double click the app (/MacOS/Flash Player) will run the movie.swf located in /Resources regardless of whether or not the info.plist file contains a swf association or not. Maybe there is one. But if there is, I'm not using it. I just want to be able to double click swfs in Finder and not have old projects open it.

Please note that if you follow these instructions and break something I probably won't have the time or the inclination to help you fix your computer. I'm only posting this as my solution to the problem I had on my computer, and yes, I did manage to break a few files, but I also managed to maintain at least 1 working copy of every project file with the modifications. So this worked for me and if you want to follow these instructions I wish you the best of luck. If you have problems, go here please.

(Oh, yeah, and these instructions are for 10.5, Leopard. There have been changes to the LaunchServices framework and the command(s) necessary to make this work on earlier or later versions of OS X are different. Don't do any of this if you either aren't running 10.5 or you aren't very comfortable in Terminal.

The first step to fixing the file associations is understanding what an application actually is in OS X. Used to be that an application was a binary file containing all kinds of resources like the icon to display, the actual executable, etcetera, but that all changed with the release of OS X. Applications were transformed into folders marked as being executable and these folders contained all of the resources broken into individual folders. It's a neat concept and it makes hacking a little easier than it used to be; now I can edit individual files within an application, cross my fingers, and see if it will still run with the changes I've made. (Note: don't do this without backing up your original .app file/folder). So what's in these magical executable folders? Right-click an .app and select "Show Package Contents" to see. There should be a folder called Contents, which holds an info.plist file, a MacOS folder, a PkgInfo file, and a Resources folder. It's the info.plist that we're interested in today.

Double clicking the plist (don't do this yet) will open the file in apple's property list editor, an application that allows you to make all kinds of modifications to how the application behaves. What I preferred to do was to open the plist in any plaintext editor (BBEdit but you could use TextWrangler, TextMate, TextEdit, pretty much any text editor that can handle an XML document) and comment out the section making a reference to the swf filetype. Here's a screenshot of how I found all of the applications from past projects (search for file name ".app" in Finder):

And here's a screenshot of the change I made; just use standard xml commenting notation to remove the dictionary item for swf type association. In other words, insert a <!-- at the beginning of the comment area and a --> at the end. There are additional associations, things like flv files, but since I almost never double click an flv I just left them in.

I did this for all .app files that I'd published from the Flash IDE. Ok, almost there; now we get to the really ugly part (as if plist editing isn't ugly enough...) Now we have to let OS X know that the file associations it's using are no good and ask it politely to generate a new list. This worked fine for me; didn't need to log out or reboot (which I'd tried after doing the plist edit and it didn't reset file associations). Running this command tells a framework in OS X that file associations should be updated. That framework is LaunchServices, the handy little part of the os that prevents it from asking you what application to use every time you click a file. It has apparently changed since 10.4 so I had to find the update utility and figure out the parameters to send it. I used:

/System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/LaunchServices.framework/Versions/A/Support/lsregister -kill -r -v -all local,system,user

Didn't need sudo (which was a surprise), it just ran through every file on my system figuring out if it was an application and what associations, if any, applied to it. By the way, the loooooong list of errors type -10811 just mean that the file it's trying to make associations for isn't an application. Pretty safe to ignore those.


And that's it. Now when I double-click a swf file it opens in the latest version of the Flash Player, for me it's the debug player 10.0.2.54 at the moment. When Adobe publishes a new debug player I'll download it, put it somewhere handy, and LaunchServices will automagically recognize it as being the most recent version and start swfs in it. Here's one last screenshot of a much, much shorter "Open With" contextual menu. I'm much less bothered now.

One last note to avoid unnecessary comments... Yes, if you publish the application again Flash will regenerate a new plist with an association to swf files. You'll need to do this hack again at that point. I recommend waiting until you're done with the project and then applying these changes to all of your prototypes and published files.