kcrawford / dockutil

command line tool for managing dock items
http://patternbuffer.wordpress.com
Apache License 2.0
1.36k stars 131 forks source link

Not updating dock during DEPNotify #117

Closed jeolsen closed 2 years ago

jeolsen commented 2 years ago

We run dockutil from DEPNotify with Jamf. During enrollmentComplete, DEPNotify is launched to inform users that their device is being setup for first time use. At the very end of the DEPNotify process we run dockutil to set the users dock up. From the logging perspective, this completes successfully. However, nothing actually happens to the dock and it stays default. If i re-run that same dockutil policy after DEPNotify finishes, it does set the dock. Nothing different is logged. If i remove dockutil as a step in DEPNotify that would still work, but wouldn't run for 15 minutes (when the next checkin occurs), so the user experience wouldn't be great.

Looking to see if there is any way to get this running during DEPNotify, but not quite sure if the issue is from the DEPNotify side or the Dockutil side. I am on the latest version of both and on macOS Monterey 12.2.1. I've tested on both Apple Silicon and Intel hardware with the same experience.

kcrawford commented 2 years ago

Doesn’t DEPNotify just show progress to the user? I’m not sure how that could be related. What options are you passing to dockutil? And this is a Jamf policy? And user is logged in?

jeolsen commented 2 years ago

@kcrawford thats correct, it just shows progress with a full screen non-movable dialog. We first deploy dockutil and ensure it is installed, then we run the following script:

!/bin/sh

echo "Removing Mail" /usr/local/bin/dockutil --remove 'Mail' --no-restart --allhomes echo "Removing Contacts" /usr/local/bin/dockutil --remove 'Contacts' --no-restart --allhomes echo "Removing Calendar" /usr/local/bin/dockutil --remove 'Calendar' --no-restart --allhomes echo "Removing Reminders" /usr/local/bin/dockutil --remove 'Reminders' --no-restart --allhomes echo "Removing Messages" /usr/local/bin/dockutil --remove 'Messages' --no-restart --allhomes echo "Removing FaceTime" /usr/local/bin/dockutil --remove 'FaceTime' --no-restart --allhomes echo "Removing Books" /usr/local/bin/dockutil --remove 'Books' --no-restart --allhomes echo "Removing Siri" /usr/local/bin/dockutil --remove 'Siri' --no-restart --allhomes echo "Removing TV" /usr/local/bin/dockutil --remove 'TV' --no-restart --allhomes echo "Removing Podcasts" /usr/local/bin/dockutil --remove 'Podcasts' --no-restart --allhomes echo "Removing iMovie" /usr/local/bin/dockutil --remove 'iMovie' --no-restart --allhomes echo "Removing Numbers" /usr/local/bin/dockutil --remove 'Numbers' --no-restart --allhomes echo "Removing Keynote" /usr/local/bin/dockutil --remove 'Keynote' --no-restart --allhomes echo "Removing Pages" /usr/local/bin/dockutil --remove 'Pages' --no-restart --allhomes echo "Removing News" /usr/local/bin/dockutil --remove 'News' --no-restart --allhomes echo "Removing Maps" /usr/local/bin/dockutil --remove 'Maps' --no-restart --allhomes echo "Removing Photos" /usr/local/bin/dockutil --remove 'Photos' --no-restart --allhomes echo "Removing Notes" /usr/local/bin/dockutil --remove 'Notes' --no-restart --allhomes echo "Removing Music" /usr/local/bin/dockutil --remove 'Music' --no-restart --allhomes echo "Removing App Store" /usr/local/bin/dockutil --remove 'App Store' --no-restart --allhomes echo "Adding Self Service" /usr/local/bin/dockutil --add /Applications/Self\ Service.app --position beginning --allhomes

exit 0

nighthawk663 commented 2 years ago

@jeolsen, out of curiosity, how are you installing dockutil and ensuring swift is installed on your computers (now that it's swift)?

Also, I think you could greatly DRY out your script by doing something more like:

dockUtil="/usr/local/bin/dockutil"
ITEMS_TO_REMOVE=(
    "App Store"
    "Siri"
    "Calendar"
    "Contacts"
    "Safari"
... etc
)
NUM_ITEMS="${#ITEMS_TO_REMOVE[@]}"
i=0

until [ "$i" -eq "$NUM_ITEMS" ]; do
   echo "Removing {ITEMS_TO_REMOVE[$i]}"
   $dockUtil --remove "${ITEMS_TO_REMOVE[$i]}" --no-restart --allhomes || true
   ((i++))
done
# Allow the restart on the last one
$dockUtil --add /Applications/Self\ Service.app --position beginning --allhomes || true

With the || true to not throw an error, you set -e at the beginning and don't need the exit 0 at the end (which will cover up any errors that you may WANT to error, like dockutil failing to install if that's earlier in the script)

Makes the script more readable repeats yourself less.

jeolsen commented 2 years ago

@nighthawk663 I'm downloading the 2.0.5 pkg file here, uploading to jamf admin (no changes to the package), then scoping it to systems with a jamf policy. the only trigger enabled is a custom one called by DEPNotify in its script.

I did look at your code and it looks more concise so i'll look to adopt that. I'm not doing anything specific for swift. All systems are macOS Monterey 12.2.1 so i believe they can run script code natively without needing to install a separate package. Re-running the dockutil script right after DEPNotify (without doing any standalone swift installations) does work.

kcrawford commented 2 years ago

The swift version is standalone pre-compiled. There is no dependency on installing anything else.

I recommend doing all testing on dockutil 3 or newer as I don't expect to backport any fixes to the python2 version.

In general you will have better luck running dockutil as the user whose Dock is being modified rather than as root with --allhomes due to the way cfprefs works. That may mean using something like outset or a LaunchAgent or running it via launchctl asuser.

kcrawford commented 2 years ago

Please retest in dockutil 3 beta 3. Some fixes may have addressed this issue.

jeolsen commented 2 years ago

Hi @kcrawford , just tested beta 3 on 12.2.1 (Intel-based). I dropped Podcasts.app on the dock an ran:

% /usr/local/bin/dockutil --version 3.0.0-beta.3 % sudo /usr/local/bin/dockutil --remove 'Podcasts' --no-restart --allhomes Remove failed for Podcasts in /var/root/Library/Preferences/com.apple.dock.plist Remove failed for Podcasts in /Users/UID/Library/Preferences/com.apple.dock.plist

Running with or without sudo didn't seem to help, and i also tried without the no-restart and allhomes options, but still got a "Remove failed". using --list doesn't show Podcasts on the dock.

kcrawford commented 2 years ago

When I tested I noticed that when you drag an item to the dock it takes some time for that to show up in cfpreferences/defaults but if I waited and confirmed it was there, dockutil worked as expected.

I don’t think that is something you’re likely to encounter in real world use.

dockutil just works with dock preferences. If the Dock process doesn’t update them I’m not sure what I could do other than provide an option to wait for an item to show up.

If you are seeing something different or other issues please post here or open another issue.

I’d like to get any remaining issues fixed very soon to get out of beta.

Thanks again for testing

jeolsen commented 2 years ago

The newer version seems to fix the issue. I had a colleague setup 3 new systems and all had their dock set correctly. Thank you

kcrawford commented 2 years ago

That’s good news! Thanks for the update. Closing this issue.