Open a URL in the Default Browser from the Command Line

Jul 18, 2011 - Leave a Comment

terminal Using the command line open tool, you can immediately launch any URL from the Terminal into the default web browser of Mac OS X. In other words, you’re launching the specified site into a GUI browser from the command line. The syntax for this is remarkably easy to use and remember:


open http://osxdaily.com

You can try this with any URL, even complex URL strings, although long query strings are best when placed into quotations. You can also use https and even specify port numbers:

open http://yahoo.com:80

Be sure to include http:// or https:// or it will look for a local file instead, while also offering a suggestion that you made an error: “Perhaps you meant ‘http://yahoo.com’?”

Remember that you can change the Mac default web browser at any time by using Safari Preferences – yes, you use Safari to change the OS X browser even if you have no intention on using Safari and want to set something like Chrome or Firefox as the default. That may be different down the road, but for now that’s the way it’s done in all versions of OS X.

The open utility comes from Mac OS X’s ancestral NextStep roots and offers the ability to launch files and GUI apps from the command line. We’ve used the open trick on numerous occasions with a variety of tips, whether just opening a GUI app, to launch multiple instances of a single app, and even to open the present working directory in Finder from the command line. It’s a powerful tool that has a lot of usage potential.

Enjoy this tip? Subscribe to the OSXDaily newsletter to get more of our great Apple tips, tricks, and important news delivered to your inbox! Enter your email address below:

Related articles:

Posted by: David Mendez in Command Line, Mac OS X, Tips & Tricks

Leave a Reply

 

Shop for Apple & Mac Deals on Amazon.com

Subscribe to OSXDaily

Subscribe to RSS Subscribe to Twitter Feed Follow on Facebook Subscribe to eMail Updates