How to Open Browser Tab From the Command Line on Mac
source link: https://betterprogramming.pub/how-to-open-browser-tab-from-the-command-line-on-mac-52744abb4905
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
How to Open Browser Tab From the Command Line on Mac
Seamlessly switch to the browser from your terminal
I was recently playing around with some bash script ideas when I had to figure out how to open a browser tab from the command line. It turns out it’s rather easy to do!
First, if you want to simply open a webpage in your default browser (not include any other options), you can simply write the below in your terminal.
open "https://medium.com"
Depending on what your default browser is, the Medium home page should be opened in a new tab. Now, if you want to get more specific with your browser, you can add that as an option. All you need to do is figure out the browser name and include an option, -a
. See below.
open -a Your\ Browser "https://medium.com"
Before we get into the Your\ Browser
part, let’s find out what -a
does with our open
command. Much like other commands, you can simply type the command without any options (-LETTER
) and click enter-the help should pop pop up.
In the help, it says that open -a
‘Opens with the specified application’. This just tells the open
command to expect an application to be what our argument is opened in. Makes sense right?
Now, onto the next part of our command: Your\ Browser
. Technically, a more accurate placeholder would be Your\ Application
but since we’re focusing on web browsers I figured Browser
was good and specific. This is basically just the name of the browser that you want to open the URL with.
For example, to open the URL in Chrome you would use google\ chrome
(not case sensitive), because Chrome’s official name is Google Chrome. If you wanted to open it in Brave, you can use brave\ browser
. If you want to find out the “official” names of the browsers on your Mac, open a new terminal window (or cd into the root of your machine) and type the following commands.
root:~ > cd /System/Volumes/Data/Applications
root:~/System/Volumes/Data/Applications > ls
Now, when I first attempted this, I tried to go through /System/Applications
, but I was unable to find any of my browser applications. Apparently, since Catalina 10.15, Macs use a “split-volume” format. What this means is that under /System/Applications
is the “system” applications; the applications that are built in to your Mac OS. Whereas /System/Volumes/Data/Applications/
will house user installed apps.
Here is a quick comparison. Below is our “user” apps listed.
Android Studio.app RingCentral.appBrave Browser.app Safari.appDocker.app Slack.app ...
And here is a list of our “system” apps.
App Store.app Launchpad.app Reminders.appAutomator.app Mail.app Shortcuts.app ...
For more on this split volume architecture, check out this Stack Overflow discussion.
So now that we can see our “user” apps, we can find out our “official” browser names. Once we find our browser names, all you need to do is take the name and add a \
right before the space between them (if applicable).
Brave Browser becomes brave\ browser
, Google Chrome becomes google\ chrome
. Safari…stays safari
.
Now that we understand this format, we can now open a tab in a browser of our choice with the command mentioned earlier in the post. Let’s try opening a tab for Medium in Brave.
> open -a Brave\ Browser "https://medium.com"
Let’s see if it worked!
And there you have it!
Alternatively, if you want to just open a blank tab you can run open -a Brave\ Browser “”
. Or, if you don’t want to open a tab but just open the application itself, you can write open -a Brave\ Browser
.
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK