2 Replies Latest reply: Sep 29, 2011 12:06 PM by Mark Jalbert
Mac Man Smith Level 1 Level 1 (15 points)

I know how add an app to the dock using unix but how do you remove one from the Dock? I have read a lot about using plistbuddy to remove it but I can not figure it out. I want to put this script in a installer/uninstaller.

  • Mac Man Smith Level 1 Level 1 (15 points)

    Got it! You can use this script:

     

     

    !/bin/bash

     

    i="$(defaults read com.apple.dock persistent-apps | grep _CFURLString\" | awk '/What ever app you want/ {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

     

     

    just save that as a executable file and you are good to go.

  • Mark Jalbert Level 5 Level 5 (4,575 points)

    Forget the looping, do the math in bash ->

    i=$(( $(defaults read com.apple.dock persistent-apps | grep _CFURLString\" | awk '/What ever app/ {print NR}') -1 ))
    /usr/libexec/PlistBuddy -c "Delete persistent-apps:$i" ~/Library/Preferences/com.apple.dock.plist
    

    Note the missing colon at the start of persistent-apps. <comment>I'm not liking this new forum software</comment>

     

    Ok, I understand why you're  looping. But it would be silly to have more than one of the same app in the dock.

     

    Message was edited by: Mark Jalbert