Scripts using "defaults write"

New Contributor II

I'm using the Sierra OS. I'm trying to run a script for hiding the menu bar on a few systems. I'm using the following as my script:

defaults write NSGlobalDomain _HIHideMenuBar -bool true
killall Finder

It says that it runs without any error but the result does not hide the menu bar or even toggle the "Automatically hide and show the menu bar" option under General in System Preferences. If I run the command locally, it works just fine. Is there some issue with doing this remotely? Is there something I'm missing?


New Contributor II

Contributor II

If it's a user specific preference you'll have to run the script as the logged in user, not as your management account that the script would run from via Remote or Policy.

If this is the case, try something like this:

user=`ls -la /dev/console | cut -d " " -f 4`

sudo -u $user defaults write NSGlobalDomain _HIHideMenuBar -bool true
sudo -u $user killall Finder


@kendalljjohnson i think the script wont work if the user is not a sudoer.

curUser=`ls -l /dev/console | cut -d " " -f 4`

defaults write /Users/$curUser/Library/Preferences/ ..... instead
sudo killall Finder

New Contributor III

@khey I used your script and it worked, however it removed all access to the script except for "system" and "everyone", with r+w and no access respectively. Once I added the admin group back in I was able to read/edit the plist but found it odd that it removed access.

Any ideas why?

edit: I checked the permissions in terminal and it now shows 'root' as the owner instead of my domain account. Wonder how it did that?

The script I used was:

#!/bin/sh curUser=ls -l /dev/console | cut -d " " -f 4 defaults write /Users/$curUser/Library/Preferences/ DSDontWriteNetworkStores TRUE

it works, just changes the ownership and access rights, weird...

New Contributor III

What about using the defaults write in files and processes?


@slundy apology, i just read this....
Actually you can also use Config Profile to disable that by default to all user instead of using a script.
To do that, go to /Library/Preferences/"the plist you want to change"/ and copy the plist and edit it with TextWrangler or something. Find the key you want to set to True or False and save it.
Go to Configuration Profile - Custom Settings and upload the plist and push it out.