Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

KeyError: 'persistent-apps' error on 10.15.4 #95

Open
ngallinger opened this issue May 11, 2020 · 6 comments
Open

KeyError: 'persistent-apps' error on 10.15.4 #95

ngallinger opened this issue May 11, 2020 · 6 comments

Comments

@ngallinger
Copy link

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'

@StephenBacon
Copy link

I am seeing the same behavior with 10.15.5.

@wreck-gar
Copy link

wreck-gar commented Jun 18, 2020

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.

@lougreenwood
Copy link

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
Copy link

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

@aaronclarke
Copy link

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

@wilchak
Copy link

wilchak commented Nov 19, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants