Scott Stevenson writes about Portable Applications on Mac OS X, commenting on how David Chartier wonders where the portable Mac OS X apps are. I’ve gotten a request from a WebnoteHappy use for a portable version of WebnoteHappy. At first I wasn’t sure what to say, but now I realize that this is really the convergence of two trends:
1. Firefox usage increasing on the Mac – and with this the Portable Firefox phenomenon
(I’ve got a popular blog post about Camino vs Firefox and it seems like a majority of the comments are pro-Firefox. Plus, Mint tells me that 46% of visitors to happyapps.com are using Safari, 37% Firefox, and Camino only garnering 8%.)
2. USB drives becoming cheap enough per megabyte to become the equivalent of a swappable hard drive
So I can easily move the location of the data files that WebnoteHappy uses to store the webnotes, folders, and smart folders so they can live on the USB drive/key. Caches could probably live on each machine, they’re just caches after all. But the preferences are still a problem. Unless you do some serious hacking and go completely away from Cocoa and Carbon, user preferences for applications always live in ~/Library/Preferences/.
Anyone up for collaborating on an open source and portable (so it can live in any directory) NSUserDefaults? I’d be interested in giving it a shot.
The only trick is – how do you specify where it would live? Maybe there would be a bootstrap mechanism that would say that all portable preferences live in /Volumes/MyUSBKey/Preferences/ or something.
An open source and portable NSUserDefaults sounds great!
Is there any way that you could detect the volume that the application is launched from and use a different path for volumes other than the one the OS is booting from?
For example if launching the application from the Mac OS X boot volume it would use ~/Library/Preferences/ and if not it would use /Preferences/ ??
I look forward to seeing some work on this! :)
The simple solution might be to look for a folder called “Library” at the same level as the application.
Instead of making an open source replacement for NSUserDefaults you might be able to get away with redefining the value of HOME in the processes environment.
Failing that – you could possibly use a persistent/volitile dictionary in the standard NSUserDefaults. That would actually be quite flexible.
Joshua: You can get the path of an application via [[NSWorkspace sharedWorkspace] fullPathForApplication:@”YourApplication”] and parse from there. Or perhaps [[NSWorkspace sharedWorkspace] activeApplication] and then look at the @”NSApplicationPath” key.
Jonathan: Well the upside of making a drop-in replacement (not sure if that’s possible, but maybe with dynamic linking) for NSUserDefaults is that you could also use it for bindings and possibly not have to redo any of your code. Just recompile. Also if it detected that you were in normal, non-portable mode, you would just delegate to the regular NSUserDefaults.
Well it’ll be interesting to see if any progress is made on this. For applications where preferences don’t change too much, this might not be a big deal as well. But I’ll try to contact Scott.
You misunderstood. I dont think either of the ways I listed would require redoing any NSUserDefaults based code. NSUserDefaults would just be using a different HOME directory or just have more defaults dictionaries attached to it.
[…] Blog « Portable WebnoteHappy? […]