# -----------------------------------------------------------------------
# A simple script to add application's icon to current user's Dock
#
# Name: addapptodock
#
# Operating System:
# Tested on 10.4 and 10.5
#
# 2009 Tony Liu
# Copyright GNU GPL
# Version 0.0.1
#
# Version History
# 0.0.1: 2009-10-23 Initial
# -----------------------------------------------------------------------
#
# Usage: see below, or run it in terminal.
#
num_argumnets=$#
if [ "$num_argumnets" -lt "1" ] ; then
echo "WARNING ! : No argument provided. Nothing added to the Dock."
echo " Usage : addapptodock /Applications/Safari.app"
exit 2
fi
App_Name="$1"
# ---------------------------
# Check if it exists
# ---------------------------
App_Check=`defaults read com.apple.dock persistent-apps | grep -w '"_CFURLString" =' | grep -i "$App_Name"`
if [ "${App_Check}" != "" ] ; then
# This item is in the dock
echo "WANRING! : Item <$App_Name> is already in the dock, it will not be added again."
exit 1
fi
# ---------------------------
# Adding Application
# ---------------------------
if [ -d "$App_Name" ] || [ -f "$App_Name" ] ; then
echo "Added <$App_Name>."
defaults write com.apple.dock persistent-apps -array-add"<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>$App_Name</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>"
else
echo "WARNING! : Could not locate Application <$App_Name>."
fi