zero-sh / apply-user-defaults

A small utility to set macOS user defaults declaratively from a YAML file.
Apache License 2.0
62 stars 1 forks source link

apply-user-defaults should handle array values #1

Open msanders opened 4 years ago

msanders commented 4 years ago

Cider storage of defaults and applying defaults doesn't appear to support arrays.

Example usage: defaults write com.apple.dock persistent-apps -array-add '{"tile-type"="spacer-tile";}'

My intention is to be able to save new persistent applications into the Dock. Since my common usage of Cider is when installing new macOS versions which keep changing the default value of com.apple.dock persistent-apps, I don't want cider apply-defaults to erase the entire persistent-apps value.

Issue reported by @RogerThiede, migrated from https://github.com/msanders/cider/issues/51.

msanders commented 4 years ago

@RogerThiede this is an interesting feature, although I'm not sure how -array-add would be represented in YAML (-array and -dict should be pretty straightforward). For managing dock items, I currently use dockutil as shown here:

brew install dockutil
dockutil --remove all --no-restart
dockutil --add /Applications/Firefox.app --no-restart
dockutil --add /Applications/Emacs.app --no-restart
dockutil --add /Applications/Utilities/Terminal.app --no-restart
dockutil --add ~/Downloads --display stack # Implicitly restarts the Dock.
RogerThiede commented 4 years ago

Thanks, I'll try out dockutil.

pdrastil commented 3 years ago

I would really appreciate the possibility to set array values as well, but only via -array flag to preserve immutability. For appending values you could use anchors that are supported in YAML syntax, however merge behaviour would be strongly preferred.

YAML sample:

com.binarynights.ForkLift-3:
  FileEditors: &editors
  - *editors
  - ApplicationPath: "/Applications/Visual Studio Code.app"
     Default: 1
     Extensions: ''

EDIT: You might have to check correct syntax and supported options of the YAML parser. Anchors are advanced feature and they are not always supported or they might have implementation differences.