Building a custom Dock dockutil.

tdenton
Contributor

Afternoon Jamf nation 

I looking for people who have successfully built a custom dock using this method here https://community.jamf.com/t5/jamf-pro/build-a-custom-macos-dock/m-p/264565

Its sort of working, it only seems to be building the dock the second time the same users logs in.

 

Any suggustion on how I can fix this behavouir as I need the dock to be created for every user that logs in when they log in. As this will eventually be deployed to a lab.


Thanks
Tom

1 ACCEPTED SOLUTION

TrentO
Contributor II

Two things:

1) Make sure all the apps you are playing in the dock are installed before your dockutil script runs. 

2) Are you running `killAll Dock` after your script? The dock needs to be reloaded after the plist is edited. Not doing this would cause the behavior you describe. 

View solution in original post

6 REPLIES 6

TrentO
Contributor II

Two things:

1) Make sure all the apps you are playing in the dock are installed before your dockutil script runs. 

2) Are you running `killAll Dock` after your script? The dock needs to be reloaded after the plist is edited. Not doing this would cause the behavior you describe. 

A killall dock at the end of script did the job thanks @TrentO 

tdenton
Contributor

@TrentO  2 would easy enough to do from jamf policy as file/process or another script.

Is there an easy way to reset the dock back to default for all users regardless of who logs in. I found plist file which appears to be controling it and removed the launch agent does seem to set it back. No idea where to start to script something like this.

 

Are using dockutil in your environment?

ttan
New Contributor

@tdenton Are you refering to reset to your custom dock or system default. 

In @mosermat GitHub link, there is section for "How to Re-load the Dock Anytime you Want" 

I configure a policy in self-service, and it works great. 

If you want to go back to system default, you should be able to do that by modifying the script. 

tdenton
Contributor

system default reseting the dock with something like this doesnt seem to work defaults delete com.apple.dock; killall Dock.

My issue is the dock doesnt load when a user logs in for the first time while "How to Re-load the Dock Anytime you Want" is an option through self service. Ideally it needs to load the custom dock when they login is'nt thats what suppose to happen?


I think running killAll Dock after the dock script maybe a soultion but havent got that far yet. I'm open to suggestions

dsavageED
Contributor III

We use dockutil v3 in a lab setup... To get the best results the code needs to be run as the logged in user, a launchagent might do this or a launchdaemon if you define the user. The code we use is ran on login trigger (jamf) and looks something like:

#!/bin/bash

DOCK_UTIL="/usr/local/bin/dockutil"

# Get logged in user
ACTIVE_USER=$( echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ && ! /loginwindow/ { print $3 }' )

if [ -z "${ACTIVE_USER}" ] || [ "${ACTIVE_USER}" == "root" ]; then
exit 0;
fi

DOCK_PREF="/Users/$ACTIVE_USER/Library/Preferences/com.apple.dock.plist"

# Function to run command as user
run_as_user() {
User_ID=$(id -u "$ACTIVE_USER")
launchctl asuser "$User_ID" sudo -u "${ACTIVE_USER}" "$@"
}

# Function for adding to Dock
add_to_dock(){
if [ -e "${1}" ]; then
echo "Adding $1 to $2"
run_as_user "${DOCK_UTIL}" --add "${1}" --section "${2}" $DOCK_PREF
fi
}

 

(add_to_dock "/Applications/Google Chrome.app" apps)