Opening OS X apps from the command line

#!/usr/bin/env bash
# By: Ernesto Jiménez <erjica@gmail.com>
#
# This script will generate aliases for all your applications
# in your /Applications folder in OS X allowing you to easily
# open applications from your command line.
# Examples:
# finder ~
# quicktime-player /path/to/video.mov
#
# I've added these lines to my $HOME/.bashrc:
# if [ -f $HOME/.bashrc_aliases ]; then
# source $HOME/.bashrc_aliases
# fi
 
echo "alias finder=\"open -a finder\"" > $HOME/.bashrc_aliases
for i in $(
  ls /Applications | awk -F / '{
if ($NF ~ /\.app$/) {
app_name = tolower($NF);
sub(/\.app/, "", app_name);
gsub(/[^a-z0-9]+/, "-", app_name);
print app_name
}
}'); do
COMMAND="open -a \\\"$(echo $i | sed -e 's/-/ /g')\\\""
    echo "alias $i=\"$COMMAND\"" >> $HOME/.bashrc_aliases
done
 
view raw This Gist brought to you by GitHub.