tags:

views:

265

answers:

1

I need a way to open a new URL in firefox from the shell on OS X. The normal way I do this is with the open command ... but the open command doesn't seem to pass query/fragment values when the location is a file: uri. Granted, this a bit of an abuse of a file uri, but if you give either FF or Safari the URI in the loc bar, they (seem to) work fine. But it appears open won't pass it.

I looked at bit at applescript, but couldn't figure out how to tell FF to open a new url, not recent versions of FF anyway. open must be communicating with the running firefox to open new urls but heck if I can figure out how it's doing it.

A: 

These worked for me on Snow Leopard if Firefox is closed:

open -a Firefox --args "http://en.wikipedia.org/wiki/Firefox#Future_developments"
open -a Firefox --args "file:///Users/nickb/test.html#ft2"

If it is already running this opens a URL in a new tab:

open -a Firefox http://en.wikipedia.org/wiki/Firefox#Future_developments

Depending on your url you may need to do more escaping/encoding to get it through the command prompt.

Also check out the Mac OS X/Linux section of this article about Firefox's command line arguments if to see what else you can do.

nick
Hmmm ... I can't replicate this. Something as simple as "open -a Firefox --args 'http://www.google.com'" causes Firefox to activate, but it doesn't load the URL. This is true for an http url, a file url, or a file path (not file:// prefix).
smparkes
The ones in the answer work for me if FF is closed. I added a line that opens the url in new tab if FF is open. I haven't figured out how to open a new window or change the current page yet if FF is already running
nick
Right ... the third line is the standard way to open a URL and /usr/bin/open will pass the fragment if the URL scheme is http, but not it's file. In that case, it strips any fragment and query part from the URL.
smparkes