I want to do something like this from a shell script:

$ open 'foo.html?foo=bar'

Sadly that fails, as it looks for a file named foo.html?foo=bar instead of foo.html before opening the browser:

The file /tmp/foo.html?foo=bar does not exist.

I noticed that open supports this for HTTP(S) URLs, though:

$ open 'https://mathiasbynens.be/demo/get?foo=bar'

So I tried to use a file:// URL:

$ open 'file:///tmp/foo.html?foo=bar'

This doesn’t error (yay), but it still only opens foo.html in the browser, without the query string appended.

So, is this possible at all?

  • I suppose one could use AppleScript… But is there really no other way? – Mathias Bynens May 10 '14 at 14:00

I don't think that you can open the file with parameters directly - even if you specify the application with

open -a "Safari" ....

Depending on what you want to accomplish you can start the built-in PHP web server with

php -S localhost:8000

and call your website with parameters like

open "http://localhost:8000/foo.html/?foo=bar"

I hope this helps.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.