KeyError: 'persistent-apps' error on 10.15.4
I am not able to add or remove anything with the latest release running on 10.15.4. I am getting the below error for each command.
dockutil --add /Applications/Microsoft\ Word.app
Traceback (most recent call last):
File "/usr/local/bin/dockutil", line 689, in
I am seeing the same behavior with 10.15.5.
Are you running this in a script via Jamf? Seems Catalina is not letting the root user modify the currently logged in user's Dock.
I've changed my script from;
/usr/local/bin/dockutil --remove 'App Store' --no-restart --allhomes
To;
user=`ls -la /dev/console | cut -d " " -f 4`
/usr/bin/sudo -u $user /usr/local/bin/dockutil --remove 'App Store' --no-restart "/Users/$user/Library/Preferences/com.apple.dock.plist"
Seems to work like that.
I'm also seeing this on Macos 12 developer beta 1.
dockutil worked for a while, but after a while of experimenting, I reset my dock (by deleting ~/Library/Preferences/com.apple.dock.plist) and I started to the get the same error.
It seems that if I run dockutil --list before dockutil --add I can work around this bug.
Not sure, but you might be experiencing the issue I filed as #109 , where the com.apple.dock.plist isn't setup yet. Dockutil expects the file to exist, and can't write elements to the persistent-apps, persistent-others, or recent-apps arrays if the arrays don't already exist.
And even if you make those manually, the Dock will completely reset itself back to a default state if you don't also have the version key set to the integer value 1
You can get around this by running this series of commands to initialize the version as 1, and fill in those expected keys with empty arrays.
defaults write <path/to/user>/Library/Preferences/com.apple.dock.plist version -int 1
defaults write <path/to/user>/Library/Preferences/com.apple.dock.plist persistent-apps -array
defaults write <path/to/user>/Library/Preferences/com.apple.dock.plist persistent-others -array
defaults write <path/to/user>/Library/Preferences/com.apple.dock.plist recent-apps -array
It seems that if I run
dockutil --listbeforedockutil --addI can work around this bug.
To anyone else who gets the "[Add|Remove] failed" error when running dockutil on a fresh user profile.... THIS IS THE SOLUTION. (Dockutil should really have some internal check to see if this is necessary and perform it automatically.) Oh well.
@aaronclarke your solution did not work for me, but I did try it.