kcrawford / dockutil

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

dockutil 3.0.0-beta.2 --allhomes as root needs killall cfprefsd #116

Closed kiepenflicker closed 2 years ago

kiepenflicker commented 2 years ago

Thanks for the Beta 2. :-) I encountered two --allhomes not working scenarios when testing it with the 12.3 Beta (21E5212f).

Scenario 1:

When I enroll a mac, log in the first user for the first time and use dockutil with the parameter --allhomes as root via sudo, the app I want to dock is written to all homes /Library/Preferences/com.apple.dock.plist but the app does not appear in the Dock after the Dock restarts. I need to do a killall cfprefsd and killall Dock to make the app appear in the Dock. After that everything behaves normally.

Scenario 2:

  1. I am logged in as User1, Execute dockutil as root with --allhomes. The app appears in the com.apple.dock.plist of every user that has this file / was logged in at least once.

  2. I log out User1 and login as User2

  3. The app is not docked and the entry in com.apple.dock.plist of User2 disappeared.

  4. I log out User2 and login as User1

  5. Execute dockutil as root with --allhomes and do a killall cfprefsd

  6. I log out User1 and login as User2

  7. The app is docked now

kcrawford commented 2 years ago

Was this working in the old python version?

kiepenflicker commented 2 years ago

Yes, it was. I retested it with 2.0.5 on 12.2.1. and the --allhomes parameter in a root session

After that I undocked all Apps, Installed 3.0.0 beta 2, rebooted and ran the same commands again. One time with a script in a Jamf policy, the other time in a root session from the Terminal. The result is that the com.apple.dock.plists for all users are populated and the Dock restarted, but no Apps are docked. After killall cfprefsd and killall Dock the Dock showed the apps. Adding other apps so that they appear after dockutil has restarted the Dock works after killall cfprefsd was executed.

kcrawford commented 2 years ago

I found 2 issues that will be resolved in the next version. They might address the issues you are seeing.

I'm still a little unclear on how to reproduce the issues if you could give me step by step instructions with exact dockutil commands and how it was run. I'd like to make sure I have the issues fixed if possible.

Also, does running it with --no-restart and then killall -9 Dock workaround the issue (without killing cfprefsd)? Does running the same dockutil command twice workaround the issue?

kiepenflicker commented 2 years ago

My workflow regarding dockutil and dock configuration is the following.

Environment:

Types of dockutil use:

Further information:

Steps to reproduce the problem I reported:

The Script is no rocket science. It is executed the following way

sudo script.sh "" "" "" "add" "/Applications/Microsoft Edge.app" "after" "Mission Control"

#!/bin/bash
set -x

DOCKUTIL="/usr/local/bin/dockutil"

if [[ ! -f "$DOCKUTIL" ]]; then
    echo "$DOCKUTIL does not exist. Bailing out here..."
    exit 0
fi

# $4 add/remove
# $5 path/name
# $6 (optional) before/after
# $7 (optional) item for before/after

if [[ "${6}" != "" ]]; then
    EXTRAPARAM="--$6"
else
    EXTRAPARAM=""
fi

if [ -d "$5" ]; then
    "$DOCKUTIL" --$4 "$5" $EXTRAPARAM "$7" --allhomes
    sleep 1
else
    echo "$5 not found. Could not dock the app."
fi
kylejericson commented 2 years ago

@kcrawford Not sure if this is the same issue or something else. When I ran this script below as root it worked every time on the old non-beta version of dockutil now on the beta it fails to run and doesn't set the dock.

#!/bin/bash echo "running dockutil" DOCKUTIL=/usr/local/bin/dockutil $DOCKUTIL --remove all --no-restart --allhomes apps=( "/System/Applications/Launchpad.app" "/Applications/Google Chrome.app" "/Applications/Microsoft Word.app" "/Applications/Microsoft Excel.app" "/Applications/Microsoft PowerPoint.app" "/Applications/Microsoft Outlook.app" "/Applications/Slack.app" "/Applications/zoom.us.app" "/Applications/Adobe Acrobat Reader DC.app" "/Applications/Box.app" "/Applications/Self Service.app" "/System/Applications/System Preferences.app" ) for app in "${apps[@]}"; do $DOCKUTIL --add "$app" --no-restart --allhomes done killall Dock exit 0

mvught commented 2 years ago

Same result here, if I run it the most of the apps are not showing in docking: Only 3 are in the docking the rest is not showing, the user is an admin. With V2 its working perfect.

!/bin/zsh

dockUtil="/usr/local/bin/dockutil"

Remove all Applications from Dock

echo "Removing all Applications" $dockUtil --remove all --allhomes

Allow the restart on the last one

$dockUtil --add '/System/Applications/Launchpad.app' --replacing 'Launchpad' --allhomes --no-restart $dockUtil --add '/System/Applications/Preview.app' --replacing 'Preview' --allhomes --no-restart $dockUtil --add '/Applications/Safari.app' --replacing 'Safari'--allhomes --no-restart $dockUtil --add '/Applications/Microsoft Edge.app' --replacing 'Microsoft Edge' --allhomes --no-restart $dockUtil --add '/System/Applications/Notes.app' --replacing 'Notes' --allhomes --no-restart $dockUtil --add '/System/Applications/Contacts.app' --replacing 'Contacts' --allhomes --no-restart $dockUtil --add '/System/Applications/Calendar.app' --replacing 'Calendar' --allhomes --no-restart $dockUtil --add '/System/Applications/App Store.app' --replacing 'App Store' --allhomes --no-restart $dockUtil --add '/Applications/Microsoft Word.app' --replacing 'Microsoft Word' --allhomes --no-restart $dockUtil --add '/Applications/Microsoft PowerPoint.app' --replacing 'Microsoft PowerPoint' --allhomes --no-restart $dockUtil --add '/Applications/Microsoft Outlook.app' --replacing 'Microsoft Outlook' --allhomes --no-restart $dockUtil --add '/Applications/Microsoft Excel.app' --replacing 'Microsoft Excel' --allhomes --no-restart $dockUtil --add '/Applications/Microsoft Teams.app' --replacing 'Microsoft Teams' --allhomes --no-restart $dockUtil --add '/System/Applications/System Preferences.app' --replacing 'System Preferences' --allhomes --no-restart $dockUtil --add '/Applications/Self Service.app' --replacing 'Self Service' --allhomes

kcrawford commented 2 years ago

Thanks. I will investigate.

kcrawford commented 2 years ago

I think I have this fixed. New release soon.

kcrawford commented 2 years ago

Thanks all for reporting and providing details on this issue. Please test in 3.0 beta 3.

kiepenflicker commented 2 years ago

The issue is gone in the Beta 3 for my workflows. :-) I have tested it on 12.2.1 and 12.3 Beta on Intel and Apple Silicon. Thank you!

kcrawford commented 2 years ago

Awesome. Glad this is working now. Thanks for all the testing and background. Closing this issue!