First I do a
defaults read > 1
Then I change the setting in the app or System Settings, then back on the commandline, I do defaults read > 2
diff 1 2
The change gets copied to a preferences.sh file with a whole bunch of statements like: defaults write com.apple.ical "Show Week Numbers" -bool true
Afterwards, I don't care where the setting is. I just set it in my preferences.sh file, and if I update any of it, I run that file.