Sometimes, it is convenient to have possibility to start/run any application (like your internet browser or text editor) directly from your terminal. Most of these applications however do not create shortcut for easy run from terminal during their installation. Below is short manual how to create this shortcut manually.
-
Open terminal (cmd + space --> type
terminal) -
Navigate to a directory where you have your code/scripts. For example
~/codeor/usr/local/bin:
$ cd ~/code
or
$ cd /usr/local/bin
Tip: If such directory does not exist, create it using (mkdir).
- Create a new
shscript for your selected application you want to run from terminal. In this case, e.g., Google Chrome. I am usingnanotext editor, so type:
$ nano chrome
Then insert following two lines into your editor:
#!/bin/bash
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome $@
(Pay attention to spaces in path to your app above. Replace them by \ )
($@ is used for paasing all input arguments from your script to your app)
Then press ctrl + O for save and ctrl + X for exit nano text editor.
- Make your script executable:
$ chmod 770 chrome
- Restart your shell, e.g.:
$ source /etc/zshr
(Modify command above based on your shell (bashrc, zshr, bash_profile,...) and location of your configuration file(~ or in etc))
(Or simply open new terminal)
- Voila! Now, you can simply start Google Chrome from terminal using
chromecommand:
$ chrome <your_webpage>
- If command above does not work, make sure that your shell config file (
/etc/zshr,/etc/bashrc, etc.) contains line with update of$PATHvariable, e.g.:
export PATH=$PATH:$HOME/code
or
export PATH=$PATH:/usr/local/bin