DockUtil - Removing persistent apps?

cscsit
New Contributor III

I'm able to get a DockUtil script to add dock items as I like, but it seems to be adding the default items as well. Is there a way to also have the script remove these I guess "persistent items'?

This is the error I'm getting when I try to remove Launchpad:

DOCKUTIL --remove 'Launchpad' --no-restart $LoggedInUserHome
Traceback (most recent call last): File "/usr/local/bin/DOCKUTIL", line 660, in <module> main() File "/usr/local/bin/DOCKUTIL", line 270, in main if removeItem(pl, remove_label): File "/usr/local/bin/DOCKUTIL", line 617, in removeItem for dock_item in pl['persistent-apps']:
KeyError: 'persistent-apps'

Here is the script I've created and it is working fine as far as adding the apps:

#!/bin/sh

LoggedInUser=$3
LoggedInUserHome="/Users/$3"

checkSetupDone() {

    if [ -f $LoggedInUserHome/Library/Preferences/com.company.docksetup.plist ] ; then
        echo "Dock has been created already for this user, skipping..."
        exit 0
    fi

}

configureDefaultDock() {

    plist=$LoggedInUserHome/Library/Preferences/com.apple.dock.plist

    echo "Logged in user is $LoggedInUser"
    echo "Logged in user's home $LoggedInUserHome"

    if [ -e /usr/local/bin/dockutil ] ; then
        dockutilVersion=`/usr/local/bin/dockutil --version`
        echo "dockutil version: $dockutilVersion"
        echo "Clearing Dock..."

        DOCKUTIL=/usr/local/bin/dockutil

        sudo $DOCKUTIL --remove all --no-restart $LoggedInUserHome 

        echo "Adding Safari..."
        $DOCKUTIL --add '/Applications/Safari.app' --no-restart $LoggedInUserHome 
        echo "Adding Activ Inspire..."
        $DOCKUTIL --add '/Applications/Promethean/Activsoftware Inspire/Inspire.app' --no-restart $LoggedInUserHome
        echo "Adding Adobe Photoshop CS5..."
        $DOCKUTIL --add '/Applications/Adobe Photoshop CS5/Adobe Photoshop CS5.app' --no-restart $LoggedInUserHome
        echo "Adding Google Chrome..."
        $DOCKUTIL --add '/Applications/Google Chrome.app' --no-restart $LoggedInUserHome 
        echo "Adding Maps..."
        $DOCKUTIL --add '/Applications/Maps.app' --no-restart $LoggedInUserHome
        echo "Adding Dictionary..."
        $DOCKUTIL --add '/Applications/Dictionary.app' --no-restart $LoggedInUserHome 
        echo "Adding Word..."
        $DOCKUTIL --add '/Applications/Microsoft Word.app' --no-restart $LoggedInUserHome 
        echo "Adding Excel..."
        $DOCKUTIL --add '/Applications/Microsoft Excel.app' --no-restart $LoggedInUserHome 
        echo "Adding PowerPoint..."
        $DOCKUTIL --add '/Applications/Microsoft PowerPoint.app' --no-restart $LoggedInUserHome 
        echo "Adding Self Service..."
        $DOCKUTIL --add '/Applications/Self Service.app' --no-restart $LoggedInUserHome  

        touch $LoggedInUserHome/Library/Preferences/com.company.docksetup.plist

    else
        echo "dockutil not installed, skipping initial dock setup..."
    fi

}

checkSetupDone
configureDefaultDock

exit 0
4 REPLIES 4

mm2270
Legendary Contributor III

You may want to enclose your script in the script marks by editing your post. Highlight everything from the #!/bin/sh down to the exit 0 and then click the button above the post edit window that looks like >_
Right now its almost impossible to read the script.

Aside from that, I'm not sure if dockutil is able to work on removing items from the persistent apps array. I don't know that I've ever tried that, so its possible it can't? Also, what OS is this being attempted on? 10.11? Or something earlier? And what JSS is the script running from, assuming you're seeing this error when it runs from a policy.

sean
Valued Contributor

What version of dockutil are you using?

Does the item you are trying to remove have a 'file-label'? dockutil uses the file-label to remove items and some items don't have a file-label! (For example, all the default Apple ones!)

cscsit
New Contributor III

@mm2270 & @sean Fixed the post so the script is easier to read. This isn't a script I created, but rather one found here. This is being used on Mac OS 10.10 and 10.11. It works as it should for adding apps, but Apple in all its glory decided on forcing apps into the dock like FaceTime, Mail, etc which I don't want in the dock. I only want the items I specify to appear in the dock.

If there's a better way of doing this feel free to suggest. I'm open to suggestions. Its just from looking around here, it seemed like everyone was managing their docks with dockutil.

Thank you for any assistance.

cscsit
New Contributor III

I was able to successfully modify my dock now using Dockutil. For some reason it isn't removing all of the dock items like its supposed to, so I just told the script to remove the ones I didn't want and added in the ones I did want. I also removed the check to see if the dock already exists part because if thats there, the script will stop.

#!/bin/sh

LoggedInUser=$3
LoggedInUserHome="/Users/$3"

#checkSetupDone() {

#    if [ -f $LoggedInUserHome/Library/Preferences/com.company.docksetup.plist ] ; then
#        echo "Dock has been created already for this user, skipping..."
#       exit 0
#    fi

#}

configureDefaultDock() {

    plist=$LoggedInUserHome/Library/Preferences/com.apple.dock.plist

    echo "Logged in user is $LoggedInUser"
    echo "Logged in user's home $LoggedInUserHome"

    if [ -e /usr/local/bin/dockutil ] ; then
        dockutilVersion=`/usr/local/bin/dockutil --version`
        echo "dockutil version: $dockutilVersion"
        echo "Clearing Dock..."

        DOCKUTIL=/usr/local/bin/dockutil

        "sudo $DOCKUTIL --remove all --no-restart $LoggedInUserHome"

        echo "Deleting Mail..."
        $DOCKUTIL --remove 'Mail' --no-restart $LoggedInUserHome 
        echo "Deleting Contacts..."
        $DOCKUTIL --remove 'Contacts' --no-restart $LoggedInUserHome
        echo "Deleting Reminders..."
        $DOCKUTIL --remove 'Reminders' --no-restart $LoggedInUserHome
        echo "Deleting FaceTime..."
        $DOCKUTIL --remove 'FaceTime' --no-restart $LoggedInUserHome 
        echo "Deleting Notes..."
        $DOCKUTIL --remove 'Notes' --no-restart $LoggedInUserHome
        echo "Deleting Messages..."
        $DOCKUTIL --remove 'Messages' --no-restart $LoggedInUserHome
        echo "Deleting Launchpad..."
        $DOCKUTIL --remove 'Launchpad' --no-restart $LoggedInUserHome
        echo "Deleting System Preferences..."
        $DOCKUTIL --remove 'System Preferences' --no-restart $LoggedInUserHome
        echo "Deleting iTunes..."
        $DOCKUTIL --remove 'iTunes' --no-restart $LoggedInUserHome
        echo "Deleting iBooks..."
        $DOCKUTIL --remove 'iBooks' --no-restart $LoggedInUserHome
        echo "Deleting App Store..."
        $DOCKUTIL --remove 'App Store' --no-restart $LoggedInUserHome 
        echo "Deleting Calendar..."
        $DOCKUTIL --remove 'Calendar' --no-restart $LoggedInUserHome 

        echo "Adding Safari..."
        $DOCKUTIL --add '/Applications/Safari.app' --no-restart $LoggedInUserHome 
        echo "Adding Activ Inspire..."
        $DOCKUTIL --add '/Applications/Promethean/Activsoftware Inspire/Inspire.app' --no-restart $LoggedInUserHome
        echo "Adding Adobe Photoshop CS5..."
        $DOCKUTIL --add '/Applications/Adobe Photoshop CS5/Adobe Photoshop CS5.app' --no-restart $LoggedInUserHome
        echo "Adding Google Chrome..."
        $DOCKUTIL --add '/Applications/Google Chrome.app' --no-restart $LoggedInUserHome 
        echo "Adding Maps..."
        $DOCKUTIL --add '/Applications/Maps.app' --no-restart $LoggedInUserHome
        echo "Adding iMovie..."
        $DOCKUTIL --add '/Applications/iMovie.app' --no-restart $LoggedInUserHome
        echo "Adding Dictionary..."
        $DOCKUTIL --add '/Applications/Dictionary.app' --no-restart $LoggedInUserHome 
        echo "Adding Word..."
        $DOCKUTIL --add '/Applications/Microsoft Word.app' --no-restart $LoggedInUserHome 
        echo "Adding Excel..."
        $DOCKUTIL --add '/Applications/Microsoft Excel.app' --no-restart $LoggedInUserHome 
        echo "Adding PowerPoint..."
        $DOCKUTIL --add '/Applications/Microsoft PowerPoint.app' --no-restart $LoggedInUserHome 
        echo "Adding Self Service..."
        $DOCKUTIL --add '/Applications/Self Service.app' --no-restart $LoggedInUserHome  

        touch $LoggedInUserHome/Library/Preferences/com.company.docksetup.plist

    else
        echo "dockutil not installed, skipping initial dock setup..."
    fi

}

checkSetupDone
configureDefaultDock

exit 0