How do I gain write permission for the defaults shell command?
-
25-05-2021 - |
Domanda
I recently migrated to a new Macbook.
If I do a $ defaults write ...
in my shell, I get an error shaped like defaults[12608:79345] Could not write domain Apple Global Domain; exiting
. Using sudo
does work, however I have some defaults that are set in my .bashrc file -- these writes did work in my old system's .bashrc, without a sudo.
Q1: Are defaults saved across reboots? If so, I can removed these from my (cluttered) .bashrc and get on with life.
Q2: If defaults are not saved across reboots, what file(s) do I need to chown or chmod in order to get the defaults write
to work quietly, in my .bashrc file?
What I've done so far:
- Read the
defaults
man page -- only seems to document the API. - Skimmed around in Apple's developer docs for Preferences. Again, this seems to be higher level API documentation for application developers who are using Cocoa.
Soluzione
The defaults
command normally writes an entry into the relevant .plist
file. The whole point of property list files is to retain settings between boots. You should not need to re-apply them after each boot.
Consequently, you should not need to run the defaults command in a .bashrc
file, which runs at the start of every interactive shell session.
You should not need sudo for defaults commands such as these:
defaults write NSGlobalDomain AppleShowScrollBars -string "Always"
defaults write -g AppleEnableMenuBarTransparency -bool false
defaults write -app Safari AutoOpenSafeDownloads -bool false
defaults write com.apple.screencapture include-date -bool false
If you're trying to write some other type of default
command to a system-level domain, then that might explain why you need sudo
. Otherwise, the need for sudo
is 'unexpected'.