Posted on 03-29-2022 10:03 AM
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
Posted on 03-30-2022 04:51 AM
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 )
Posted on 04-15-2022 12:27 AM
Hi Bol,
Could you share your sample script?
I tried, but mine is not working.
Thanks!
Posted on 04-17-2022 04:33 AM
@rajrajan 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
Posted on 08-23-2022 10:45 AM
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.
Posted on 08-23-2022 10:48 AM
Here is how I have the policy in Jamf setup...
Posted on 04-17-2022 11:56 PM
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.
Posted on 04-18-2022 12:28 AM
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 )
Posted on 11-08-2022 09:33 AM
I had to add a kill Dock in the script for the -remove dock command to work.
Posted on 11-08-2022 09:33 AM
Sorry killall Dock
Posted on 09-30-2022 05:56 AM
Posted on 12-28-2022 04:35 PM
Thanks for sharing this one, bro!