When you’re working on your Mac, you might occasionally need to open a browser from the command line with a specific URL. This could be for any number of reasons. Perhaps you’re scripting an automation task, or you’re trying to debug a web application. In any case, it can be efficient to perform this task directly from the terminal. Here’s a step-by-step guide to achieving this.
To open a new browser window from the terminal with a specific URL, you would use the open
command in the terminal. open
is a versatile command used in the UNIX command line for Mac that allows you to invoke various types of applications or files, including web URLs.
Here’s the syntax to use:
open -a "Browser Name" "http://www.example.com"
Replace Browser Name
with the name of the web browser you wish to open (Safari, Google Chrome, Firefox, etc.) and replace http://www.example.com
with your desired URL.
As an example, let’s say you want to open Google Chrome to the website https://www.google.com
. You would type the following command into your terminal:
open -a "Google Chrome" "https://www.google.com"
Once you press Enter
, Google Chrome should open and navigate to Google’s homepage.
Before we wrap up, keep in mind that your browser’s name must be spelled and capitalized exactly as it appears in your Applications folder. Additionally, if the name contains spaces, you’ll need to encase it in quotation marks.
To automate this further, you could incorporate this command into a shell script or terminal alias to speed up repetitive tasks.
We hope you found this guide on how to open a browser with a specific URL from the command line on Mac useful. So, the next time you need to quickly launch a browser to a specific webpage via command line, simply invoke the open
command, and you’re there in a snap!