3

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.
1

1 Answer 1

3

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'.

5
  • 1
    Plist is really the last place to look for defaults since it now reads and writes to a consolidated database and only tangentially persists to a file for backwards compatibility. developer.apple.com/documentation/foundation/userdefaults
    – bmike
    Commented Dec 28, 2019 at 18:25
  • I am running from an admin account, however I did have to do an account rename because my home directory got transferred over with the wrong name. That's probably the source of the 'unexpected'. Thank you for the clarification about preferences!
    – LiavK
    Commented Dec 28, 2019 at 18:25
  • You said, "If you're running from an admin account, then that would be 'unexpected'." ... An Admin account still needs to use sudo when using defaults write ... to a file owned by root, which /Library/Preferences/.GlobalPreferences.plist is. Commented Dec 28, 2019 at 19:57
  • @user3439894 I can do defaults write -g without using sudo.
    – benwiggy
    Commented Dec 28, 2019 at 23:48
  • benwiggy, ls -l /Library/Preferences/.GlobalPreferences.plist outputs -rw-r--r-- 1 root wheel ... and since it is owned by root and there is no write permissions for Group and Other the latter which the Admin account falls under, you cannot, under default normal conditions write to /Library/Preferences/.GlobalPreferences.plist without the use of sudo from an Admin account! defaults write -g without specifying the PLIST filename writes to ~/Library/Preferences/.GlobalPreferences.plist not /Library/Preferences/.GlobalPreferences.plist Commented Dec 29, 2019 at 1:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .