If you're going to open URLs frequently, there are a few ways to dramatically increase efficiency. The easiest way is to use bash aliases. An alias allows you to basically create a shortcut for longer commands.
Alias for opening URLs in Chrome
Here are a few examples (you can add them to your ~/.bash_profile
).
alias gc="open -a Google\ Chrome"
Or if you'd like to create an alias to the command that let's you specify a profile, you could do the following:
alias gc="/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --profile-directory=Profile\ 5"
Anytime you edit your bash_profile, you need to run source ~/.bash_profile
or open a new shell to see the changes take effect.
With this, you can run:
gc # Open or focus on the Chrome window
gc https://howchoo.com # Open the url in Chrome
Similarly, the gc {url}
command will open the url in Chrome, but it will use the specified profile every time.
Alias that accepts a URL from STDIN
In some cases, you might want to accept a URL from STDIN. The open
command handles stdin the way we'd like, so if you're using the first alias, you don't need to do anything.
If you're using the alias for Google Chrome
, one easy way is to create a second alias (using xargs) like this:
alias gcx="xargs /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --profile-directory=Profile\ 5"
This will allow you to do something like this:
echo "https://howchoo.com" | gcx
If you've got a better way of doing this, let me know in the comments below :)