Controlling Firefox via Command Line

Mozilla-based browsers like Firefox have inherited a useful feature from the good old Netscape Navigator: Controlling a running browser instance via the command line. Using command line options, you can open URLs or files inside your browser window without having to enter them in the address bar.

Suppose you’re working in a terminal and want to open an HTML file in your current working directory:

  firefox -remote "openurl(file://`pwd`/filename.html)"

Your browser should then open the file in a new tab.

Unfortunately, this is a lot to type, so I wrote a python script called b (for “browser”) which simplifies this. The command above can now be written like this:

  b filename.html

Any number of files may be given on the command line. The script supports absolute and relative file names, directories, and URLs. Whitespace and unprintable characters are handled correctly, too.

See the documentation at for more information about the remote control feature.

This entry was posted in python and tagged , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s