Posted on
08-19-2019
08:52 AM
- last edited on
03-04-2025
06:36 AM
by
kh-richa_mig
Hey all,
I'm looking for help modifying this Dock Master script to ignore the part about the user template and to just install in the current user that's logged in. I want to create a policy to apply once per user per computer, on login. Can anyone help me tweak this?
#!/bin/bash
# Apply dock to existing user accounts.
APPLY_DOCK_TO_EXISTING_USERS=false
# A dock plist placed in the User Template directory is applied to new user accounts.
USER_TEMPLATE_DOCK_PLIST="/System/Library/User Template/English.lproj/Library/Preferences/com.apple.dock.plist"
# Currently logged in user.
CURRENTLY_LOGGED_IN_USER=$(/usr/bin/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 + "
");')
if [[ "$APPLY_DOCK_TO_EXISTING_USERS" == "true" ]]
then
# Output local home directory path (/Users/username).
for USER_HOME in /Users/*
do
# Extract account name (a.k.a. username) from home directory path.
ACCOUNT_NAME=$(/usr/bin/basename "${USER_HOME}")
# If account name is not "Shared".
if [[ "$ACCOUNT_NAME" != "Shared" ]]
then
USER_DOCK_PLIST="${USER_HOME}/Library/Preferences/com.apple.dock.plist"
# If the account already contains a dock plist.
if [[ -f "$USER_DOCK_PLIST" ]]
then
echo "Removing existing user dock plist."
/usr/bin/defaults delete "$USER_DOCK_PLIST"
fi
echo "Copying the latest dock plist into place."
cp "$USER_TEMPLATE_DOCK_PLIST" "$USER_DOCK_PLIST"
echo "Updating permissions to match user (${ACCOUNT_NAME})."
/usr/sbin/chown -R "$ACCOUNT_NAME" "$USER_DOCK_PLIST"
# Reboot the dock if a user is currently logged in.
if [[ "$CURRENTLY_LOGGED_IN_USER" == "$ACCOUNT_NAME" ]]
then
# Update cached dock plist.
/usr/bin/sudo -u "$ACCOUNT_NAME" /usr/bin/defaults read "$USER_DOCK_PLIST"
# Relaunch the dock process.
/usr/bin/killall Dock
fi
fi
done
fi