macos: how to open any app from the command line

2022-07-27

 | 

~1 min read

 | 

197 words

One of my favorite things about VS Code is how easy it is to open a new project from the terminal. The application has it built right into their command palette. (I wrote about how to set it up here).

I’ve recently started using GoLand as an IDE. It’s fully featured and particularly good for Golang, which I’m working in more these days. The problem, however, was that I now had years of muscle memory for opening up VS Code from the command line. Did GoLand support this?

Short answer: Yes (on any operating system).

Slightly longer answer: On a POSIX system, opening GoLand from the command line leverages the open command. To make this particularly easy, you can add an alias to your zshrc.

.zshrc
// .zshrc
alias goland="open -na \"GoLand.app\" --args "

Then, to use it:

% goland ~/path/to/project

The particularly nice thing about this is that there’s no magic. This is the pattern you’d use for any application. On a Mac, your applications are found in the /Applications directory (two levels above your home directory).

And just like that, we have a way to open any app from the command line!



Hi there and thanks for reading! My name's Stephen. I live in Chicago with my wife, Kate, and dog, Finn. Want more? See about and get in touch!