nix-darwin icon indicating copy to clipboard operation
nix-darwin copied to clipboard

fix writing values with containers

Open dfrankland opened this issue 10 months ago • 0 comments

Currently, the -array value for writeValue produces incorrect arguments for defaults like so

-array -string 'blah' -string 'blah'

Complex container values like -array and -dict have their own DSL which does not allow specifying all data types. Instead of using the DSL use plist fragments instead.

The man page for defaults writes the following, below. This doesn't give much guidance on passing values with containers, but there's an undocumented feature to pass plist fragments for much more complex use-cases: https://shadowfile.inode.link/blog/2018/06/advanced-defaults1-usage/#container-types

...
     write domain key 'value'
                  Writes value as the value for key in domain.  value must be a property list, and must be enclosed in single quotes.  For example:

                        defaults write com.companyname.appname "Default Color" '(255, 0, 0)'

                  sets the value for Default Color to an array containing the strings 255, 0, 0 (the red, green, and blue components). Note that the key is enclosed in quotation marks because it contains a space.

     write domain 'plist'
                  Overwrites the defaults information in domain with that given as plist.  plist must be a property list representation of a dictionary, and must be enclosed in single quotes.  For example:

                        defaults write com.companyname.appname '{ "Default Color" = (255, 0, 0);
                                                        "Default Font" = Helvetica; }';

                  erases any previous defaults for com.companyname.appname and writes the values for the two names into the defaults system.
...
     -array      Allows the user to specify an array as the value for the given preference key:

                       defaults write somedomain preferenceKey -array element1 element2 element3

                 The specified array overwrites the value of the key if the key was present at the time of the write. If the key was not present, it is created with the new value.

     -array-add  Allows the user to add new elements to the end of an array for a key which has an array as its value. Usage is the same as -array above. If the key was not present, it is created with the specified
                 array as its value.

Depended on by: #619

dfrankland avatar Oct 11 '23 07:10 dfrankland