System preferences can be set on macOS using the defaults command. For example, say I wish set the Prevent sleep setting that can be set through the System Preferences interface, but instead via command line.

If your settings match those in the screenshot above, running defaults read /Library/Preferences/com.apple.PowerManagement.plist in the terminal should output
{
"AC Power" = {
"Automatic Restart On Power Loss" = 1;
DarkWakeBackgroundTasks = 1;
"Disk Sleep Timer" = 180;
"Display Sleep Timer" = 5;
"Display Sleep Uses Dim" = 1;
GPUSwitch = 2;
"System Sleep Timer" = 15;
"Wake On LAN" = 1;
};
"Battery Power" = {
"Automatic Restart On Power Loss" = 1;
DarkWakeBackgroundTasks = 0;
"Disk Sleep Timer" = 180;
"Display Sleep Timer" = 5;
"Display Sleep Uses Dim" = 1;
GPUSwitch = 2;
ReduceBrightness = 1;
"System Sleep Timer" = 10;
"Wake On LAN" = 1;
};
SystemPowerSettings = {
DestroyFVKeyOnStandby = 0;
"Update DarkWakeBG Setting" = 1;
};
}
To set System Sleep Timer to 0, run /usr/libexec/PlistBuddy -c "Set 'AC Power':'System Sleep Timer' 0" /Library/Preferences/com.apple.PowerManagement.plist. Now running the original defaults read command will output
{
"AC Power" = {
"Automatic Restart On Power Loss" = 1;
DarkWakeBackgroundTasks = 1;
"Disk Sleep Timer" = 180;
"Display Sleep Timer" = 5;
"Display Sleep Uses Dim" = 1;
GPUSwitch = 2;
"System Sleep Timer" = 0;
"Wake On LAN" = 1;
};
"Battery Power" = {
"Automatic Restart On Power Loss" = 1;
DarkWakeBackgroundTasks = 0;
"Disk Sleep Timer" = 180;
"Display Sleep Timer" = 5;
"Display Sleep Uses Dim" = 1;
GPUSwitch = 2;
ReduceBrightness = 1;
"System Sleep Timer" = 10;
"Wake On LAN" = 1;
};
SystemPowerSettings = {
DestroyFVKeyOnStandby = 0;
"Update DarkWakeBG Setting" = 1;
};
}
Now opening the System Preferences will reveal the updated value.






















