At least as early as Mac High Sierra (10.13.4), defaults write
(e.g., whether of the form defaults write com.example.test '{a = (b, 2);}'
or defaults write com.example.testb "a" '(b, 2)'
) is creating binary plist files for me in ~/Library/Preferences/
even when the file hasn't yet been created.
And it can be created at a particular path by swapping a domain with the desired file path, e.g.,
defaults write "/users/brett/Desktop/com.example.testc" "a" '(b, 2)'
The XML syntax also works:
defaults write "/users/brett/Desktop/com.example.testc" '<dict><key>a</key><array><string>b</string><string>2</string></array></dict>'
(Supplying JSON does not work (despite plist
being able to convert it to JSON).)
One can also use defaults import
to create a new binary plist file, whether defaults import <domain> -
which lets you (via stdin) use either of the syntaxes above (or defaults import <domain> pathToExistingPlist
, assuming the referenced plist is itself a binary file).
Finally, one can use defaults export
on an existing file, assuming it is expressed as XML or the ASCII property list (or another binary plist).
defaults export com.example.test1 /path/for/com.example.testcopy.plist
The latter is similar to the behavior of the plutil command in the answer by @user495470 except that it will only copy in place if you specify a path in the second argument which leads to the same file as that referenced in the first (domain).
With the exception of the latter export
syntax (which creates an empty <dict>
upon finding a non-dict type at root), for any of the above, errors are given when trying anything but a dict at root.