PDA

View Full Version : Editing System Prefs




jnoxx
Jun 17, 2011, 08:17 AM
Hey everyone,

I code iOS alot. But I tried taking a step to the Mac OSX, after one of my collegues asked me to make something "little", all I want to do, is create a YES/NO Function for a certain System Setting.
So let's say I want to disable a certain System setting, like, "Expose" by code.
Is it possible, couldn't find a good google answer, only 1 on stackoverflow, but no one answered there ;)

Thanks alot :)


Regards, Noxx



subsonix
Jun 17, 2011, 08:48 AM
If it's a certain system setting, why don't you mention exactly what it is instead of an unrelated example.

robbieduncan
Jun 17, 2011, 09:15 AM
In general the answer is no. It may be possible by gaining admin access and altering specific plist files that represent the preferences or by using GUI Applescripting.

chown33
Jun 17, 2011, 12:25 PM
In general the answer is no. It may be possible by gaining admin access and altering specific plist files that represent the preferences or by using GUI Applescripting.

I think the general answer is "Maybe", and it may need some detective work.

Many preferences are stored here:
~/Library/Preferences
~/Library/Preferences/ByHost

They are usually plist files, so they can be read and written using the 'defaults' and 'plutil' commands.

The detective work is figuring out which file, where it's located, and which key belongs to which GUI element in the prefpane. Even then, it may not be accessible easily. For example, the Time Machine disk is stored as a data object, probably an alias-record.

System-wide preferences are stored here:
/Library/Preferences
/Library/Preferences/ByHost

and they may be writable without elevated privileges.

There are other places that settings might be stored. It depends on the pref-pane, so knowing exactly what setting to change is crucial.


Certain system configuration preferences are stored here:
/Library/Preferences/SystemConfiguration

and they should only be accessed by the 'scutil' command.

There are other specific commands that are the proper way to access a configurable element, rather than 'defaults' or 'plutil'. This command lists them:
ls -1 /usr/*bin/*{util,setup}

Then plug their names into the 'man' command to read their respective man pages.


If necessary, use the 'authopen' command for elevating privileges, rather than 'sudo'. See 'man authopen'.

Hansr
Jun 17, 2011, 01:06 PM
So let's say I want to disable a certain System setting, like, "Expose" by code.

Provided your application runs with admin priv or prompts the user for admin privs on the execution of the command you can spin up a CLI process and just send:

defaults write com.apple.dock mcx-expose-disabled -bool true ;killall Dock