Mass Remove Dock Icons: dockutil script

tnielsen
Valued Contributor

I wrote this because I got tired of rewriting scripts every year when Adobe adds/changes or replaces the names of their applications. It was just boring writing that stuff.

Here is a script that will mass remove based on keywords. Enjoy:

#!/bin/bash
#Requires dockutil to be installed at /usr/local/bin
#https://github.com/kcrawford/dockutil
#tnielsen 10-26-18

#Remove anything that matches the following condition that is in the list.  In my case, I want to remove all adobe dock icons.
remove="Adobe"

function RemoveDockIcon () {
/usr/local/bin/dockutil --remove $1 --no-restart --allhomes
}
IFS=$'
'
apps=()
apps=($(dockutil --list | grep $remove | awk -F'file:' '{print $1}' | awk 'BEGIN{ RS = "" ; FS = "
" }{print $0}'))

#if we don't find anything, don't do anything.
if [ ! -z "$apps" ]; then
for x in ${apps[@]}; do
    #Remove the trailing spaces
    x="$(echo -e "$x" | sed -e 's/[[:space:]]*$//')"
    echo "Removing $x from the Dock"
    RemoveDockIcon $x
done
killall cfprefsd 2>&1
killall Dock 2>&1
exit 0
fi

echo "Nothing was removed"
4 REPLIES 4

jmjenki3
New Contributor II

Awesome! This exactly the thing I have been meaning to develop myself! Thank you for posting this. I will be implementing in my site ASAP.

tnielsen
Valued Contributor

I need to add two lines to this code. When I was testing, it runs as current user but won't have access to remove items from allhomes.
One sec, quick fix.

tnielsen
Valued Contributor

I added the code to get the current user's home directory and scan the dock items from there. You can modify this however you want, obviously. I think I may improve this by replacing the user's current dock items with new ones for only those that he/she had previously put on there.

I'll do that monday. I hate you Adobe! :)

#!/bin/bash
#Requires dockutil to be installed at /usr/local/bin
#https://github.com/kcrawford/dockutil
#tnielsen 10-26-18

#Remove anything that matches the following condition that is in the list.  In my case, I want to remove all adobe dock icons.
remove="Adobe"

currentUser=$(ls -l /dev/console | awk '{print $3}')
userHome=$(dscl . read /Users/$currentUser NFSHomeDirectory | awk '{print $2}')

#NOTE: should probably check if current user is logged in.  we also dont care if current user is root and would exit.  will add that later.  worst case it just doesn't remove anything and may error out.  no harm, though.

function RemoveDockIcon () {
/usr/local/bin/dockutil --remove $1 --no-restart --allhomes
}
IFS=$'
'
apps=()
apps=($(dockutil --list --homeloc $userHome | grep $remove | awk -F'file:' '{print $1}' | awk 'BEGIN{ RS = "" ; FS = "
" }{print $0}'))

#if we don't find anything, don't do anything.
if [ ! -z "$apps" ]; then
for x in ${apps[@]}; do
    #Remove the trailing spaces
    x="$(echo -e "$x" | sed -e 's/[[:space:]]*$//')"
    echo "Removing $x from the Dock"
    RemoveDockIcon $x
done
killall cfprefsd 2>&1
killall Dock 2>&1
exit 0
fi

echo "Nothing was removed"

jhuls
Contributor III

@tnielsen Did you rewrite this script so that it replaces the specific Adobe icons that are already in the dock? If so, any chance you could share it? Thanks.