DockUtil Script shows briefly shows question mark icons before showing the proper dock.

KeithStrand
New Contributor III

I have a policy called "Dock CleanUp" triggered at login, once per user per computer.

Script works as expected except I always briefly get question marks for missing apps until the

killall Dock
sleep 5
killall Dock

Then after the sleep the dock appears as desired.

The apps are present before the sript is run.

 

Is there anything obvious I'm missing? Thanks in advance for taking a look.

 

Cheers

 

Script is below:

#!/bin/bash

########## Clean Dock Up ###########

sudo -u $(ls -l /dev/console | awk '{print $3}') /usr/bin/defaults delete com.apple.dock persistent-apps
sudo -u $(ls -l /dev/console | awk '{print $3}') /usr/bin/defaults delete com.apple.dock persistent-others
sudo -u $(ls -l /dev/console | awk '{print $3}') /usr/bin/defaults write com.apple.dock show-recents -bool false

########## Add Apps to the Dock #########
sudo -u $(ls -l /dev/console | awk '{print $3}') /usr/bin/defaults write com.apple.dock persistent-apps -array-add '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>file:///Applications/Google Chrome.app</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>'
sudo -u $(ls -l /dev/console | awk '{print $3}') /usr/bin/defaults write com.apple.dock persistent-apps -array-add '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>file:///Applications/Slack.app</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>'

sudo -u $(ls -l /dev/console | awk '{print $3}') /usr/bin/defaults write com.apple.dock persistent-apps -array-add '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>file:///System/Applications/System Settings.app</string><key>_CFURLStringType</key><integer>0</integer></dict></dict></dict>'


########## User variable ##########
user=`ls -l /dev/console | awk '{print $3}'`
documents='<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>/Users/'$user'/Documents</string><key>_CFURLStringType</key><integer>0</integer></dict><key>showas</key><integer>2</integer><key>arrangement</key><integer>2</integer><key>displayas</key><integer>1</integer></dict><key>tile-type</key><string>directory-tile</string></dict>'
downloads='<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>/Users/'$user'/Downloads</string><key>_CFURLStringType</key><integer>0</integer></dict><key>showas</key><integer>2</integer><key>arrangement</key><integer>2</integer><key>displayas</key><integer>1</integer></dict><key>tile-type</key><string>directory-tile</string></dict>'

sudo -u $(ls -l /dev/console | awk '{print $3}') /usr/bin/defaults write com.apple.dock persistent-others -array-add '<dict><key>tile-data</key><dict><key>file-data</key><dict><key>_CFURLString</key><string>/Applications/</string><key>_CFURLStringType</key><integer>0</integer></dict><key>showas</key><integer>3</integer><key>arrangement</key><integer>1</integer><key>displayas</key><integer>1</integer></dict><key>tile-type</key><string>directory-tile</string></dict>'
sudo -u $(ls -l /dev/console | awk '{print $3}') /usr/bin/defaults write com.apple.dock persistent-others -array-add $documents
sudo -u $(ls -l /dev/console | awk '{print $3}') /usr/bin/defaults write com.apple.dock persistent-others -array-add $downloads

####using Killall Dock twice to test #####
####sudo killall Dock
killall Dock
sleep 5
killall Dock

 

2 REPLIES 2

sdagley
Esteemed Contributor II

@KeithStrand The subject of your post mentions DockUtil, but your script is just using the defaults tool to write Dock configuration data. If you were using dockutil (https://github.com/kcrawford/dockutil), which is a popular tool for scripting Dock configuration changes, it includes a --no-restart option which prevents the Dock from updating until changes are complete. If you want to eliminate the visual anomalies from your approach you might want to give dockutil a try.

KeithStrand
New Contributor III

Thanks, yeah I realized I'd made that mistake. I will take another look at dockutil and see if I can get it to work.

Thank you for taking the time. Appreciate it.

_ Cheers