My question may have a ridiculously easy answer, but here goes. We have a lab environment with a teacher who works with grades Pre-K, K, 1, 2, 3.
We have user accounts (standard user accounts in AD for these grades).
The teacher wanted to have a specific dock configuration for these standard user accounts. After looking at a bunch of options I went with Dockutil.
A friend of mine with considerably more scripting experience helped me create a single script that used case to configure the dock for those specific user accounts.
The trouble is that script was made before Dockutil was rebuilt using Swift. How do I adapt the script to work now without Python??
The script is below:
#!/bin/bash
#We need to wait for the dock to actually start
until [[ $(pgrep Dock) ]]; do
wait
done
#Get the current logged in user that we'll be modifying
if [ ! -z "$3" ]; then
user=$3
else
user=$(python -c 'from SystemConfiguration import SCDynamicStoreCopyConsoleUser; import sys; username = (SCDynamicStoreCopyConsoleUser(None, None, None) or [None])[0]; username = [username,""][username in [u"loginwindow", None, u""]]; sys.stdout.write(username + "\\n");')
fi
#Set variables
du="/usr/local/bin/dockutil"
userHome="/Users/$user"
networkHome="smb://server.com/Students$/$user"
#Function for applying dock configuration
createBaseDock()
{
#Remove all items for logged in user
$du --remove all --no-restart $userHome
#Adding base items to the dock
$du --add '/Applications/Google Chrome.app' --position 1 --no-restart $userHome
$du --add '/Applications/Safari.app' --position 2 --no-restart $userHome
$du --add '/Applications/Comic Life 3.app' --position 3 --no-restart $userHome
$du --add '/Applications/The Print Shop 4.app' --position 4 --no-restart $userHome
$du --add '/Applications/KID PIX.app' --position 5 --no-restart $userHome
}
#Function for finishing base dock
finishBaseDock()
{
#Add local downloads
$du --add '~/Downloads' --section others --position last --no-restart $userHome
killall Dock
}
case $user in
p|k)
echo "p or k found"
createBaseDock
finishBaseDock
;;
1)
echo "1 found"
createBaseDock
$du --add '/System/Applications/Photo Booth.app' --position 6 --no-restart $userHome
finishBaseDock
;;
2)
echo "2 found"
createBaseDock
$du --add '/System/Applications/Photo Booth.app' --position 6 --no-restart $userHome
finishBaseDock
;;
3)
echo "3 found"
createBaseDock
$du --add '/System/Applications/Photo Booth.app' --position 6 --no-restart $userHome
$du --add '/Applications/Adobe Photoshop 2020/Adobe Photoshop 2020.app' --position 7 --no-restart $userHome
finishBaseDock
;;
esac
exit 0