Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'bash version' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
bash version
Authored by: semios on Apr 03, '02 07:42:40PM

I broke part of it into a script, but it's essentially the same thing. Place the following file make_alias in your ~/bin directory (make one if necessary mkdir ~/bin).

#!/bin/bash
# make_alias

for file in "$@"; do
    if [ -e "$file" ]; then
        app=$(basename "$file" .app)
        name=$(echo $app | perl -pe 'tr/A-Z/a-z/; s/[s()]+//g;');
        echo "alias ${name}='open -a "${app}"';"
        #echo "function ${name} () { open -a "${app}" "$@" & }"
    else
        echo "No such file: $file";
    fi
done

In your ~/.bash_profile insert the following code

OSXDIRLIST="/Applications /Developer/Applications ${HOME}/Applications"
ALIASDIR="${HOME}/.osxaliases"
if [ ! -e $ALIASDIR ]; then
  mkdir $ALIASDIR
fi
for dir in $OSXDIRLIST; do
  if [ ! -d $dir ]; then
        echo "No such dir: $dir";
  else
  file=`echo $dir | sed -e 'y#/#_#'`
  if [ "$dir" -nt "$ALIASDIR/$file" ]; then
    echo "Updating $dir aliases..."
    rm -f "$ALIASDIR/$file"
    find $dir -name '*.app' -prune -exec make_alias {} >> "$ALIASDIR/$file" ;
  fi
  source $ALIASDIR/$file
  fi
done

That should do it for all you bash fiends.

[ Reply to This | # ]

bash version
Authored by: beehive on Apr 04, '02 11:01:40AM

Actually that should be:
find $dir -name '*.app' -prune -exec make_alias {} ':' >> "$ALIASDIR/$file"
you also might want to use:
name=$(echo $app | perl -pe 'tr/A-Z/a-z/; s/[( )]+//g;');
instead (Strips spaces instead of stripping s's)


I didn't like the check all time so I modified this for a nightly cron

make_alias file:

#!/bin/sh

for file in "$@"; do
if [ -e "$file" ]; then
app=$(basename "$file" .app);
name=$(echo $app | perl -pe 'tr/A-Z/a-z/; s/[( )]+//g;');
echo "alias ${name}='open -a "${app}"'";
else
echo "No such file: $file";
fi
done


and gen_aliases file:

#!/bin/sh

OSXDIRLIST="/Applications /Developer/Applications ${HOME}/Applications"
ALIASFILE="${HOME}/.aliases"
: > $ALIASFILE

if [ ! -e $ALIASDIR ]; then
mkdir $ALIASDIR
fi

for dir in $OSXDIRLIST; do
if [ -d $dir ]; then
find $dir -name '*.app' -prune -exec make_alias {} ';' >> "$ALIASFILE"
fi
done


cron gen_aliases and to .bash_profile add:

source .aliases




[ Reply to This | # ]