dockutil icon indicating copy to clipboard operation
dockutil copied to clipboard

KeyError: 'persistent-apps' error on 10.15.4

Open ngallinger opened this issue 5 years ago • 6 comments

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 main() File "/usr/local/bin/dockutil", line 388, in main if addItem(pl, real_add_path, replace_label, position, before_item, after_item, section, displayas, showas, arrangement, tile_type, label_name): File "/usr/local/bin/dockutil", line 565, in addItem for existing_dock_item in (pl[section]): KeyError: 'persistent-apps'

ngallinger avatar May 11 '20 19:05 ngallinger

I am seeing the same behavior with 10.15.5.

StephenBacon avatar Jun 17 '20 13:06 StephenBacon

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.

wreck-gar avatar Jun 18 '20 04:06 wreck-gar

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.

lougreenwood avatar Jun 27 '21 20:06 lougreenwood

It seems that if I run dockutil --list before dockutil --add I can work around this bug.

lougreenwood avatar Jun 27 '21 20:06 lougreenwood

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

aaronclarke avatar Oct 16 '21 00:10 aaronclarke

It seems that if I run dockutil --list before dockutil --add I 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.

wilchak avatar Nov 19 '22 00:11 wilchak