CommandLine

Handling command line arguments with XULRunner

For Multiple Instances Application

It's fairly easy to retrieve application specific command line arguments in XULRunner when it's not a single instance application. An nsICommandLine object is passed as the first argument of the launched window:

Example

For single instance applications

Of course, for a single instance application (see toolkit.singletonWindowType for more information), the last example still applies the first time your application is launched. However, if you'd like to retrieve the latest command line arguments (to open a file for example), a possible solution is to create your own command line handler.

For the sake of simplicity, the proposed solution involves the observer service to notify observers that the updated arguments are available. A similar and better way to implement this solution is by defining argument specific handlers with registering and unregistering functions in your command line handler service. This has the advantage to accumulate unhandled arguments until a specific handler is added. This approach has been used in Songbird.