Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Setting System/App parameters from terminal

Way too long question, I know :-( Sorry

I often completely erase my computer and do a Clean Install. But there is a lot of setting I like to redo, and I’d like to do a part of it in a bash script that I would run on fresh install.


I need help on two thing


1- Writing parameters inside parameter (sorry for my English)

When the parameter is in the first level, I can do it

Example

defaults write com.apple.Terminal "Default Window Settings" Homebrew

defaults write com.apple.Terminal "Startup Window Settings" Homebrew


But when it is not on the first level, I don’t know how to do

Example

if I wanted to create a new entry in NSUserDictionaryReplacementItems

(Might be a bad example because those comeback even on clean install but it is just to illustrated)

User uploaded file



Question 1


how to write those multi level parameter



2- Looking for parameter

To find which parameter to change in a preferences files

I change a parameter in the preference of the App I need to configure

then I look into my ~/Library/Prerefences to see which file has changed


But something, I don’t see which file has been changed

Example

system Preference -> General -> Use Dark menu bar and dock

When I toggle it, I don’t see which preference file is being used

so in terminal, I tried

grep -r 'mode' ./

I tried with many different word, and could not find it


Question 2

any suggestions on how to search :-)


Thank you

Posted on Apr 11, 2018 9:42 AM

Reply
Question marked as Best reply

Posted on Apr 11, 2018 10:40 AM

Hello Franco,

This key is in the domain "Apple Global Domain". You won't find it in your home directory. You are never really guaranteed to find it in a file. The defaults system only uses files for persistence. They aren't guaranteed to have updated values.


The easiest way to find something is to run "defaults read" to list everything. Then you can narrow it down with:

defaults read "Apple Global Domain"


Then you need to do something like:

defaults write "Apple Global Domain" NSUserDictionaryReplacementItems -array-add '{ on = 1; replace = jrv; with = "J’arrive\!";}'


Note my creative use of smart quotes because I can't figure out the escaping of a single quite inside a double quote inside a single quote on the command line.


Unfortunately, this doesn't appear to work. It updates the defaults setting, but the UI seems to have its own set of data and it always overrides the defaults settings.

Similar questions

14 replies
Question marked as Best reply

Apr 11, 2018 10:40 AM in response to Franco Borgo

Hello Franco,

This key is in the domain "Apple Global Domain". You won't find it in your home directory. You are never really guaranteed to find it in a file. The defaults system only uses files for persistence. They aren't guaranteed to have updated values.


The easiest way to find something is to run "defaults read" to list everything. Then you can narrow it down with:

defaults read "Apple Global Domain"


Then you need to do something like:

defaults write "Apple Global Domain" NSUserDictionaryReplacementItems -array-add '{ on = 1; replace = jrv; with = "J’arrive\!";}'


Note my creative use of smart quotes because I can't figure out the escaping of a single quite inside a double quote inside a single quote on the command line.


Unfortunately, this doesn't appear to work. It updates the defaults setting, but the UI seems to have its own set of data and it always overrides the defaults settings.

Apr 11, 2018 11:10 AM in response to etresoft

there is other kind of item that give me problem

In the Preference in Script Editor,

When I toggle “Show Script Menu in menu bar”

2 entry appear in com.apple.systemuiserver.plist


User uploaded file


I try to write this

defaults write com.apple.systemuiserver.plist menuExtras -array-add “/System/Library/CoreServices/Menu\ Extras/Script\ Menu.menu”

defaults write com.apple.systemuiserver.plist "NSStatusItem Visible com.apple.scriptmenu" -bool true


and it seem to work

Is there a way to find which process to restart to see the change ?




oh, I just realize, to remove an entry from an array -del , -remove ?

defaults write com.apple.systemuiserver.plist “menuExtras” -array -del “/System/Library/CoreServices/Menu Extras/Script Menu.menu”


if fact, it will be better to know where to read about those array :-)

Apr 11, 2018 11:34 AM in response to VikingOSX

oh another one to keep

Thank you


this guy tell many ways to get a man pages, his last one, I kept

Armin Briegel - The macOS School of Terminal Witchcraft and Wizardry - YouTube

in the bash profile, we have to add


function xman () {

open x-man-page://$1 ;

}


and type xman keyword in terminal to get the default yellow man page (two finger scrollable and customizable in terminal pref.)


the whole video is pretty good,

Apr 11, 2018 12:42 PM in response to Franco Borgo

There are a number of GitHub sites that list interesting and useful command line settings:

https://github.com/mathiasbynens/dotfiles/blob/master/.macos

https://github.com/herrbischoff/awesome-macos-command-line

https://gist.github.com/rafaelstz/9aaf791ca081dcafb3a9


Anytime you change one of these settings, you will need to kill the cfprefsd process like this:

killall cfprefsd


Then, any newly opened apps should see the new settings. This only applies to preferences in the user domain. If you are hacking around in a global domain, you may need to restart. And, as always, any particular setting may not work at any given time depending on many factors.

Setting System/App parameters from terminal

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.