Remove Dock Icons

From AFP548 Wiki
Jump to: navigation, search

First off, a big thanks to frogor from the irc channel, this is largely his doing.

This script is born of the need to remove the icons for apps in folders. The specific situation was removing the Office 2008 icons before installing Office 2011.

!/bin/bash
 
i="$(defaults read com.apple.dock persistent-apps | grep _CFURLString\" | awk '/Microsoft Office 2008/ {print NR}')"
 
for  j in `echo "$i" | tr " " "\n" | sort -gr`
 
do
	/usr/libexec/PlistBuddy -c "Delete persistent-apps:$[$j-1]" ~/Library/Preferences/com.apple.dock.plist
done
 
killall Dock

This script can be pasted into Automator under the Run Shell Script item to create an app or workflow to remove the dock icons.

It works by pulling the persistant app number from the users dock plist (~/Library/Preferences/com.apple.dock.plist) and placing them in the variable $i as an array.

The for loop reverses the numbers in the $i array, places the numbers if a greatest first order in the $j variable and uses plistbuddy to delete those values from the dock plist. The reversal is needed because if you delete icon 2, icon 3 becomes 2. Going from highest to lowest eliminates the moving target.

The last command (killall Dock) refreshes the dock to show the changes.