Add Application Icon to the Dock

This script shows how to add an application icon to the dock's list of persistent applications. This could be useful for developers to offer users the option of adding their application's icon to the dock, or for system administrators who want to programmatically add items to the dock in a script.

 

Usage...

Enter the posix-style path of the application you want to add to the dock in the "theAppPath" variable declaration on the first line. Then run the script.

Code...

set theAppPath to "/Applications/Chess.app"
try
	set theShellScript to "defaults write com.apple.dock persistent-apps -array-add '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>" & theAppPath & "</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>'"
	do shell script theShellScript
	do shell script "killall -HUP Dock"
end try

Notes...

Be aware that the "killall" command restarts the dock, causing it to dissappear briefly. Also, error-checking should be added to confirm the existence of the application before attempting to add it to the dock. If you attempt to add an application that doesn't exist at the specified path, an entry will be made anyways, and a default "?" icon will appear in the dock.

 

 

Hosted by www.Geocities.ws

1