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 13, '06 06:14:59AM
Okay - I think this is the last version; while looking at vtron's concerns, I realized that the mdfind command wasn't right. (You have to love a program that simply ignores invalid arguments and doesn't tell you about them!) Anyway, the previous mdfind versions always included all applications, whether they were in the specified directories or not. This version handles them correctly and does a better job of dealing with applications that have spaces in their names and don't end in ".app"


# -------------------------
# 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,/\//);
                        name = path[count];
                        name = tolower(name);
                        gsub(/ |\(|\)|\"|'\\\''|\.app/, "", 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 | # ]