Feature request - add --remove_missing
Add a --remove_missing (or similar) option. This would remove dock items which are 'missing' their target applications and are therefore showing a '?' instead of the application icon.
Is this even possible?
Turns out it is possible. Here is a Bash Script that does just that. I'd create a pull request however you wouldn't be able to stop laughing at my Python. Would be a worthwhile feature add maybe?
echo "---------Remove broken icons from the Dock----------"
myArray=()
# create a loop to cycle through all the persistant items in the dock.
for ((x=0;x>=0;x+=1));
do
# get the name of the App at position x
name=`/usr/libexec/PlistBuddy -c "Print persistent-apps:$x" ~/Library/Preferences/com.apple.dock.plist | grep -a "file-label"`
if [ ! $? -eq 0 ]; then
# the command failed so we've got to the end of the dock items. Break out.
echo "Plist Buddy comand failed so we got to the end of the dock items; breaking out"
break;
fi
echo $name
#remove some chars from the beginning of the string to clean it up.
name=${name:21}
echo "App is : $name"
# get the file location of the App
location=`/usr/libexec/PlistBuddy -c "Print persistent-apps:$x" ~/Library/Preferences/com.apple.dock.plist | grep -a "_CFURLString"`
location=${location:68}
# clean up the location string.
replace="%20"
with=" "
result_string="${location/\%20/ }"
echo "App path is : $result_string"
# test to see if the App exists (actually that it doesn't exist)
if [ ! -d "$result_string" ]
then
# doesn't exist therefore it has a broken icon. Add it to our array.
echo "$name has a broken icon"
myArray=("${myArray[@]}" "$name")
fi
echo ""
done
echo ${myArray[@]}
for i in "${myArray[@]}"
do
dockutil --remove "$i"
done
echo echo "---------Done Removing broken icons from the Dock----------"
I like the idea but we may need to do more validation. I haven't looked into it, but I suspect problems if the path is on a server that is not mounted. Or it might not be a file or folder dock item.
Kyle
On Oct 23, 2014, at 5:10 PM, dwkns [email protected] wrote:
Turns out it is possible. Here is a Bash Script that does just that. I'd create a pull request however you wouldn't be able to stop laughing at my Python. Would be a worthwhile feature add maybe?
echo "---------Remove broken icons from the Dock----------" myArray=()
create a loop to cycle through all the persistant items in the dock.
for ((x=0;x>=0;x+=1)); do
get the name of the App at position x
name=
/usr/libexec/PlistBuddy -c "Print persistent-apps:$x" ~/Library/Preferences/com.apple.dock.plist | grep -a "file-label"if [ ! $? -eq 0 ]; then # the command failed so we've got to the end of the dock items. Break out. echo "Plist Buddy comand failed so we got to the end of the dock items; breaking out" break; fi
echo $name#remove some chars from the beginning of the string to clean it up. name=${name:21} echo "App is : $name"
get the file location of the App
location=
/usr/libexec/PlistBuddy -c "Print persistent-apps:$x" ~/Library/Preferences/com.apple.dock.plist | grep -a "_CFURLString"location=${location:68}clean up the location string.
replace="%20" with=" " result_string="${location/%20/ }"
echo "App path is : $result_string"
test to see if the App exists (actually that it doesn't exist)
if [ ! -d "$result_string" ] then
doesn't exist therefore it has a broken icon. Add it to our array.
echo "$name has a broken icon" myArray=("${myArray[@]}" "$name")fi echo "" done
echo ${myArray[@]} for i in "${myArray[@]}" do dockutil --remove "$i" done
echo echo "---------Done Removing broken icons from the Dock----------" — Reply to this email directly or view it on GitHub.