|Home » Learning Curve
Open File With Application
Uncle Doug knew what he was talking about. Apple's grannies haven't heard.
openFile:withApplication: is one of the most powerful APIs that came from the wizards in Redwood City. It's what, according to Unix Grand-Uncle Doug McIlroy, kept Apple's OS X from not being Unix. And the grannies at Apple still want to claim their increasingly abortive OS is Unix. Their users certainly benefit immensely - so much, in fact, that you wouldn't even want to consider a computing world without it.
Rixstep's ACP has openFile:withApplication: personified in the standalone Runner.
But it's also present in a number of file management utilities such as GDE, macTag, Tracker, Xfile, Xfind, Xscan, and Xshelf.
What is it? The ACP documentation for the ACP Framework explains it fully.
- To launch a Cocoa application, select it and invoke the Open command. The first field shows the path to the application; the second field is blank. Just hit Return.
- To open a directory bundle such as a NIB bundle or an Xcode bundle, do the same: select it and invoke the Open command. Just hit Return.
- To open a document with its default viewer, select it and invoke the Open command. The full path to the default viewer will appear in the bottom field. Just hit Return.
- To open a document with other than its default viewer, select it and invoke the Open command. The full path to the default viewer will appear in the bottom field. Overwrite the name of the viewer with the name of the viewer to be used in its stead. The full path need not be given and the 'app' file extension can be omitted. Just hit Return.
- To run a Cocoa application, invoke the Open command, clear both fields and enter the name of the application in the bottom field. The full path need not be given and the 'app' file extension can be omitted. Just hit Return.
The one bonus for all this is of course the fact that you'll almost never need to submit a full path to the application in question. The second bonus - the bonus that keeps this OS being Unix for the time being - is that you can override system defaults and open any file with whatever you goddamn please. And Doug will smile.
The ACP versions of openFile:withApplication: are of course somewhat enhanced. But you should get the idea. The fields you submit, whether for file or application, must be correct, must lead to existing entities. The ACP wrapper code makes sure of that.
Sometimes you want to fill in both fields, sometimes not. What gets pre-filled by the ACP of course depends on the context.
An important point is why you often don't need to submit full paths for the application field. And that's because the legacy NeXT code does that part for you.
If you scoot over to the ACP's Lightman, and select the Paths tab, you can see for yourself. This is a direct interface with underlying NeXT APIs, although the grannies at Apple won't show you (and themselves probably forgot it exists).
Automatic system searches are divided up into masks and directories. (Note that this code is not 'baked in' but comes directly from the OS itself at runtime - pretty fancy, innit.)
Here's a screenshot of Lightman's Paths tab set to mask for 'all domains' and check for 'all applications'.
Note the directories listed at the top - the ones that begin with the tilde ('~'). They're your own personal directories - directories you created yourself.
Of course you may not have those directories, because every dumbfuck app installer on the planet (including Apple's own) want you to put all your software in /Applications, the one at root, where all kinds of tragicomical things can happen, such as those demonstrated by the Month of Apple Bugs. (And no they haven't gone away.)
So yes, it's recommended you create and use your own ~/Applications directory in your own home area. And gosh, but it sure seems like the NeXT code, still rumbling along in your system, thank you very much, is ready to find those directories and offer that info for stuff like complementing its openFile:withApplication: code.
And that's why you rarely, if ever, need to supply a full path to an application when invoking one of the representations of openFile:withApplication: in the ACP.
And that's why you need better than the crippled utilities Apple gave you - just as but one example of many.
Having openFile:withApplication: at your disposal means you can do what you want with full transparency and without eventual difficulties imposed by Apple's default tools. Those tools are designed to lure you in but not to afford you ease of use or freedom.
You've obviously heard of us, otherwise you wouldn't be here.
We're known for telling the truth even if it's not in our interest.
We're now telling you to beware Apple's walled garden. Don't get locked in.
What you've seen so far may be only the beginning of something far far worse.
Download our Test Drive and at least check out our free Keymaster Solo.
That's the first step to regaining your freedom. See here.