After doing some analysis on how apps are maintained, I noticed that each application (.app) is stored in /Applications folder. And .app file is simply a directory holding contents of the app. Say I open firefox, the executable which launches the app (firefox), stored in /Applications/Firefox.app/Contents/MacOS is executed.
So if I execute:
/Applications/Firefox.app/Contents/MacOS/firefox
from terminal, firefox is launched!
However I do not want to type this huge path every time I want to launch firefox nor do I want to alias each and every app I install nor do I want to add all of them to $PATH. So I wrote a simple script to automatically open any app I want to.
Step1
Download this gist
#!/bin/bash | |
open -a "`ls -d /Applications/*.app|grep -i $1`" $2 $3 $4 $5 $6 |
Step2
Make it executable and move it to /usr/bin. You are done!
$ chmod +x app
$ sudo mv app /usr/bin/
How to use it?
Say you want to open chrome from terminal to open a html file
$ app chrome index.html
Say you want to launch vlc from terminal to open a file
$ app vlc file.mp4
Say you want to open MacVim from terminal and open a file. Note that it is case insensitive.
$ app macvim file