2

I want to be able to type a short command and have that be replaced with a longer one. For example, typing vscode could run something like open -a "Visual Studio Code". I know this is possible in Linux, but is there any way to do this in MacOS?

Thanks in advance!

1
  • did you get it to work?
    – Natsfan
    Jun 29, 2020 at 23:18

2 Answers 2

3

You should be able to do the same as your were doing in Linux in macOS.

As an example, if using bash, adding

alias vscode="open -a 'Visual Studio Code'"

to your .bash_profile file will let you just type vscode in Terminal to open Visual Studio Code.


Note: If you are running macOS Catalina, or later, and have not installed a more recent version of bash and are using the default zsh shell, then put aliases in your ~/.zprofile, or the appropriate file for the shell you are running.

Also, you might want to read Visual Studio Code on macOS to add the code executable to your PATH or path, depending on your shell.

3
  • Better answer than mine. But mine should work. Takes a little longer. I have about 30 aliases in my .bash_profile file yet I didn't even think of doing it that way! lol
    – Natsfan
    Jun 27, 2020 at 3:03
  • 1
    Note that starting in macOS Catalina, the default interactive shell is zsh, so you'd put that in ~/.zprofile instead of ~/.bash_profile. Jun 27, 2020 at 3:04
  • 2
    Or you could just follow VS Code's published instructions, at code.visualstudio.com/docs/setup/… . But no one reads instructions. Jun 29, 2020 at 21:23
0

You could write a series of 1 line scripts and make them executable. In your example, a script named vscode would contain the one line you describe above. then you could

chmod +x vscode

and then just type vscode and return to run it.

1
  • You need to first add a shebang and then your script code, so not really one-liners. Jun 27, 2020 at 3:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .