Having trouble editing Finder settings using defaults write

command linedefaultsfinder

I run the following command:

sudo defaults write ~/Library/Preferences/com.apple.finder.plist ShowHardDrivesOnDesktop -boolean TRUE

in hopes that this will cause system hard drives to show on the desktop, which doesn't happen. I kill all Finder processes and restart Finder, but no dice.

I try to open com.apple.finder.plist in Xcode, but it says I do not have permissions to view the file (I was able to before). Shortly after, I am able to open it, but the file is empty. The attributes are slowly regenerating.

What is happening here? I am looking for a command to toggle the option to show hard drives on the desktop, just as if I checked the box in Finder preferences.

Best Answer

First of all you shouldn't need sudo and it may have caused the permissions issue, and no need to use the full pathname, just:

defaults write com.apple.finder ShowHardDrivesOnDesktop -boolean TRUE

The following works for me, as is, in OS X 10.8.5 and macOS 10.12.5 in both a Standard and Admin Account in Terminal.

defaults write com.apple.finder ShowHardDrivesOnDesktop -boolean TRUE; killall Finder

Using FALSE, in place of TRUE hides the e.g. Macintosh HD on the Desktop.

I'd probably opt to either restore the file from a known good backup or delete the ~/Library/Preferences/com.apple.finder.plist file and then run killall Finder in Terminal, letting it rebuild and should resolve the permissions issue as well.