Wednesday, 17 March 2010

Neat OS X terminal-trick for quickly launching apps

Applications on OS X resides in the /Application folder. They are usually a pain to start from the terminall/shell.
You usually have to do something like this open -a /Application/Safari.app to launch safari.
I made this nice, useful one-liner, that creates an alias for every app. It lowercases the name of the app and it removes whitespaces. Safari becomes safari, "Quicktime Player" becomes quicktimeplayer.

The most useful to me is "vlc movie.avi", "0xed binaryfile.bin" and "textmate textfile.txt"

Put this into ~/.zshrc an you have aliases for all your apps
for app in /Applications/*.app;do;alias ${${app//(\.app| |\/Applications\/)/}:l}="open -a \"$app\"";done


You could also put Utilities into aliases with
for app in /Applications/Utilities/*.app;do;alias ${${app//(\.app| |\/Applications\/Utilities\/)/}:l}="open -a \"$app\"";done
You now have nice commands like: diskutility, console, activitymonitor


PS. You need zsh for this script. (just run chsh from shell and change /bin/bash to /bin/zsh).

2 comments:

  1. You don't need the full path and name for launching Applications, a simple

    open -a Safari

    will do also..

    ReplyDelete
  2. But you need to include /Applications if you want to enumerate the apps and create aliases and tab-completion

    ReplyDelete