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


Click here to return to the 'Automatically create app-launching aliases in bash' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Automatically create app-launching aliases in bash
Authored by: porkchop_d_clown on Jul 12, '06 07:39:14PM
I like the idea of using mdfind; some of the other changes you made don't seem to be an improvement, though. The way you update SPOTLIGHT_SEARCH means that if one directory changes, only that directory will written to the new alias file - losing the aliases from the other directories.

Anyway, I took your version and combined it with mine. For example, the only reason I used multiple alias files was to reduce the time spent running find. Since that isn't needed with mdfind, we don't need an entire directory to hold the aliases, and since it serves no purpose, we don't need the sort. Actually, we also don't need a bunch of terminal backslashes either, since they are inside a quoted string.

Here's the newest version:

# -------------------------
# Build application aliases
# -------------------------
export ALIASFILE="$HOME/.osxaliases"
OSXDIRLIST=(/Applications /Developer/Applications $HOME/Applications)

UPDATE=0
for dir in ${OSXDIRLIST[@]}; do
    SPOTLIGHT_SEARCH="${SPOTLIGHT_SEARCH} --onlyin \"$dir\""
    if [[ -d "$dir" && "$ALIASFILE" -ot "$dir" ]]; then
        UPDATE=1
    fi
done

if (( $UPDATE )); then
    echo "Updating aliases..."
    mdfind \
        $SPOTLIGHT_SEARCH \
        "kMDItemContentType == 'com.apple.application-bundle'" \
        | awk\
            '{
                appl = $0;
                count = split(appl,path,/\/|\.app|\.dock/);
                name = path[count-1];
                name = tolower(name);
                gsub(/ |\(|\)|\"|'\\\''/, "", name);
                gsub(/'\''/, "'\''\\'\'\''", appl);
                gsub(/\"/, "\\\"", appl);
                printf "alias %s=\"open -a %c%s%c\"\n",name,39,appl,39;
            }' >| $ALIASFILE
else
    echo "Aliases are up to date."
fi

source $HOME/.bashrc

---
Everyone loves a clown, but no one will lend him money!

[ Reply to This | # ]

Automatically create app-launching aliases in bash
Authored by: koncept on Jul 13, '06 12:05:58AM

Nice stuff! :)



[ Reply to This | # ]