dockutil script revised for Monterey

Becci
New Contributor

With Python not being automatically installed as part of Monterey, the old script to adjust the dock once dockutil is installed doesn't work as written. 

Here is a sample of a script that has been revised to work with Monterey and dockutil 3.0.2

 

#!/bin/bash
# NEW DockUtil Script without python v2.2

# Include Standard PATH for commands
export PATH=/usr/bin:/bin:/usr/sbin:/sbin
# Set up variables
whoami="/usr/bin/whoami"
echo="/bin/echo"
sudo="/usr/bin/sudo"
dockutil="/usr/local/bin/dockutil"
killall="/usr/bin/killall"
loggedInUser=$( echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ && ! /loginwindow/ { print $3 }' )
LoggedInUserHome="/Users/$loggedInUser"
UserPlist=$LoggedInUserHome/Library/Preferences/com.apple.dock.plist

##########################################################################################
# Check if script is running as root
##########################################################################################
$echo

if [ `$whoami` != root ]; then
    $echo "[ERROR] This script must be run using sudo or as root. Exiting..."
    exit 1
fi

##########################################################################################
# Use Dockutil to Modify Logged-In User's Dock
##########################################################################################
$echo "----------------------------------------------------------------------"
$echo "Dockutil script to modify logged-in user's Dock"
$echo "----------------------------------------------------------------------"
$echo "Current logged-in user: $loggedInUser"
$echo "----------------------------------------------------------------------"
$echo "Removing all Items from the Logged-In User's Dock..."
$sudo -u $loggedInUser $dockutil --remove all --no-restart $UserPlist

$echo "Creating New Dock..."
$echo
$echo "Adding \"Finder\"..."

$echo "Adding \"Google Chrome\"..."
$sudo -u $loggedInUser $dockutil --add "/Applications/Google Chrome.app" --no-restart $UserPlist

$echo "Adding \"Google Slides\"..."
$sudo -u $loggedInUser $dockutil --add "/Applications/Google Slides.app" --no-restart $UserPlist

$echo "Adding \"Google Sheets\"..."
$sudo -u $loggedInUser $dockutil --add "/Applications/Google Sheets.app" --no-restart $UserPlist

$echo "Adding \"Google Docs\"..."
$sudo -u $loggedInUser $dockutil --add "/Applications/Google Docs.app" --no-restart $UserPlist

#$echo "Adding \"Acrobat\"..."
#$sudo -u $loggedInUser $dockutil --add "/Applications/Adobe Acrobat DC/Adobe Acrobat.app" --no-restart $UserPlist

$echo "Adding \"VLC\"..."
$sudo -u $loggedInUser $dockutil --add "/Applications/VLC.app" --no-restart $UserPlist

$echo "Adding \"Manager\"..."
$sudo -u $loggedInUser $dockutil --add "/Applications/Manager.app" --no-restart $UserPlist

$echo "Adding \"System Preferences\"..."
$sudo -u $loggedInUser $dockutil --add "System/Applications/System Preferences.app" --no-restart $UserPlist

$echo "Adding \"Chrome Apps\"..."
$sudo -u $loggedInUser $dockutil --add "~/Applications/Chrome Apps.localized" --section others --view grid --display folder --no-restart $UserPlist

$echo "Adding \"Downloads\"..."
$sudo -u $loggedInUser $dockutil --add "~/Downloads" --section others --view auto --display folder --no-restart $UserPlist

$echo "Restarting Dock..."
$sudo -u $loggedInUser $killall Dock

exit 0

 

11 REPLIES 11

Bol
Valued Contributor

Kudos! 

I just finished revising this for a site this week. I found there's no need to run as user via sudo -u, just adding the users plist location to the command worked for me and this is run via login or self service.

Previously my script would run as user but I couldn't get that to work anymore ( well done to you! :D ) with the new binary written in swift! ( Very cool of Mr Crawford to update with all things Python considered )

Raj_Jenkin
New Contributor III

Hi Bol,

Could you share your sample script? 

I tried, but mine is not working.

 

Thanks!

Bol
Valued Contributor

@Raj_Jenkin Of course, good luck with it. Let me know if there's any issues.

#!/bin/zsh

dockutilbin=$(/usr/bin/which dockutil)
loggedInUser=$( echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ && ! /loginwindow/ { print $3 }' )
loggedInUserPlist="/Users/$loggedInUser/Library/Preferences/com.apple.dock.plist"

$dockutilbin --remove all --no-restart $loggedInUserPlist; sleep 2
$dockutilbin --add file:///System/Applications/Launchpad.app/ --no-restart $loggedInUserPlist
$dockutilbin --add file:///Applications/Safari.app/ --no-restart $loggedInUserPlist
$dockutilbin --add file:///System/Applications/Calendar.app/ --no-restart $loggedInUserPlist
$dockutilbin --add file:///System/Applications/Dictionary.app/ --no-restart $loggedInUserPlist
$dockutilbin --add file:///Applications/Microsoft\ Word.app/ --no-restart $loggedInUserPlist
$dockutilbin --add file:///Applications/Microsoft\ Excel.app/ --no-restart $loggedInUserPlist
$dockutilbin --add file:///Applications/Microsoft\ PowerPoint.app/ --no-restart $loggedInUserPlist
$dockutilbin --add file:///Applications/Microsoft\ OneNote.app/ --no-restart $loggedInUserPlist
$dockutilbin --add file:///Applications/Self\ Service.app/ --no-restart $loggedInUserPlist
$dockutilbin --add file:///Applications/PCClient.app/ --label Papercut --no-restart $loggedInUserPlist
$dockutilbin --add file:///System/Applications/System\ Preferences.app/ --no-restart $loggedInUserPlist
$dockutilbin --add '/Applications/' --view grid --display folder --sort name --no-restart $loggedInUserPlist
$dockutilbin --add '~/Downloads/' --view fan --display folder --sort name $loggedInUserPlist

exit 0

 

kwoodard
Contributor III

I followed this to a "T" and I still cannot get this to run. I have tried my old docutil script as well, also cannot get it to run. What I used to do was have a launchagent setup in the English.lprog folder that would call the script when a user logged in. I have been unable to get that working either (I assume because of the sandboxing in the newer macOS). Trying to get this going on the most recent Monterey...

My original script, that has worked for many years...

#!/bin/bash

# Running checkSetupDone function to determine if the rest of this script needs to run.
# Yes, if $HOME/Library/Preferences/com.ARC.docksetup.plist file does not exist.
# Otherwise, assume this setup script has already run for this user and does not
# need to run again.

#We need to wait for the dock to actually start
until [[ $(pgrep Dock) ]]; do
    wait
done

checkSetupDone()    {

    if [ -f $HOME/Library/Preferences/com.ARC.docksetup.plist ] ; then
        exit 0
    fi

}

configureDefaultDock()  {

    DOCKUTIL=/usr/local/bin/dockutil

    $DOCKUTIL --remove all --no-restart

    $DOCKUTIL --add '/System/Applications/Launchpad.app' --no-restart

    $DOCKUTIL --add '/Applications/Safari.app' --no-restart
    
    $DOCKUTIL --add '/Applications/Google Chrome.app' --no-restart
    
    $DOCKUTIL --add '/Applications/Adobe Bridge 2022/Adobe Bridge 2022.app' --no-restart
    
    $DOCKUTIL --add '/Applications/Adobe Photoshop 2022/Adobe Photoshop 2022.app' --no-restart
    
    $DOCKUTIL --add '/Applications/Adobe Lightroom Classic/Adobe Lightroom Classic.app' --no-restart
    
    $DOCKUTIL --add '/Applications/Adobe Illustrator 2022/Adobe Illustrator.app' --no-restart
    
    $DOCKUTIL --add '/Applications/Adobe Premiere Pro 2022/Adobe Premiere Pro 2022.app' --no-restart
    
    $DOCKUTIL --add '/Applications/Adobe Substance 3D Designer/Adobe Substance 3D Designer.app' --no-restart
    
    $DOCKUTIL --add '/Applications/Adobe Substance 3D Painter/Adobe Substance 3D Painter.app' --no-restart
    
    $DOCKUTIL --add '/Applications/Autodesk/maya2023/Maya.app' --no-restart
    
    $DOCKUTIL --add '/Applications/TVPaint Animation 11.5 Pro.app' --no-restart
    
    $DOCKUTIL --add '/Applications/Corel Painter 2021/Corel Painter 2021.app' --no-restart
    
    $DOCKUTIL --add '/Applications/VLC.app' --no-restart
    
    $DOCKUTIL --add '/Applications' --view grid --display folder --sort name

    touch $HOME/Library/Preferences/com.ARC.docksetup.plist

}

checkSetupDone
configureDefaultDock

defaults write com.apple.dock tilesize -int 40
defaults write com.apple.dock magnification -bool true

exit 0

 

New Script... I did make a change to point to my current docutil. Since I have been using it for so long, I am now unsure if this is where the current version of docutil installs too.

#!/bin/zsh

dockutilbin=$(/usr/local/bin/dockutil)
loggedInUser=$( echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ && ! /loginwindow/ { print $3 }' )
loggedInUserPlist="/Users/$loggedInUser/Library/Preferences/com.apple.dock.plist"

$dockutilbin --remove all --no-restart $loggedInUserPlist; sleep 2
$dockutilbin --add file:///System/Applications/Launchpad.app/ --no-restart $loggedInUserPlist
$dockutilbin --add file:///Applications/Safari.app/ --no-restart $loggedInUserPlist
$dockutilbin --add file:///Applications/Google\ Chrome.app/ --no-restart $loggedInUserPlist
$dockutilbin --add file:///Applications/Adobe\ Bridge\ 2022/Adobe\ Bridge\ 2022.app/ --no-restart $loggedInUserPlist
$dockutilbin --add file:///Applications/Adobe\ Photoshop\ 2022/Adobe\ Photoshop\ 2022.app/ --no-restart $loggedInUserPlist
$dockutilbin --add file:///Applications/Adobe\ Lightroom\ Classic/Adobe\ Lightroom\ Classic.app/ --no-restart $loggedInUserPlist
$dockutilbin --add file:///Applications/Adobe\ Illustrator\ 2022/Adobe\ Illustrator.app/ --no-restart $loggedInUserPlist
$dockutilbin --add file:///Applications/Adobe\ Premiere\ Pro\ 2022/Adobe\ Premiere\ Pro\ 2022.app/ --no-restart $loggedInUserPlist
$dockutilbin --add file:///Applications/Adobe\ Substance\ 3D\ Designer/Adobe\ Substance\ 3D\ Designer.app/ --no-restart $loggedInUserPlist
$dockutilbin --add file:///Applications/Adobe\ Substance\ 3D\ Painter/Adobe\ Substance\ 3D\ Painter.app/ --no-restart $loggedInUserPlist
$dockutilbin --add file:///Applications/Autodesk/maya2023/Maya.app/ --no-restart $loggedInUserPlist
$dockutilbin --add file:///Applications/TVPaint\ Animation\ 11.5\ Pro.app/ --no-restart $loggedInUserPlist
$dockutilbin --add file:///Applications/Corel\ Painter\ 2021/Corel\ Painter\ 2021.app/ --no-restart $loggedInUserPlist
$dockutilbin --add file:///Applications/VLC.app/ --no-restart $loggedInUserPlist
$dockutilbin --add '/Applications/' --view grid --display folder --sort name --no-restart $loggedInUserPlist
$dockutilbin --add '~/Downloads/' --view fan --display folder --sort name $loggedInUserPlist

exit 0

 @Bol I just modified your script to see if I can get this started, then I will make any changes I need specific to my labs.

Here is how I have the policy in Jamf setup...

General sectionGeneral sectionScript sectionScript section

Raj_Jenkin
New Contributor III

Hi Bol,

Brilliant! 

Work like a charm. However, how do I execute this during login? And why is it not working when pushed from Jamf School to macOS Monterey client machine?

 

Thanks!

Raj.

Bol
Valued Contributor

I added the script to Jamf Pro, then created a new policy which triggers on login, adding this script to the payload section. ( I have already installed the new dockitil pkg during startup ) 

Im not quite sure but I’ve only tested this script on macOS 12.3 with no issues ( python being removed ) 

ptrondsen-mgni
New Contributor II

I had to add a kill Dock in the script for the -remove dock command to work.

Sorry killall Dock

mosermat
New Contributor III

Hey @Raj_Jenkin. I know this post is a little dated now but I just came across it. If you still need to automate your custom Dock during login you can check out my post here. I created a step-by-step guide on how to do this and it still works great as of now at the current MacOS, Ventura 13.0. 

Raj_Jenkin
New Contributor III

Thanks for sharing this one, bro!