Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jnoxx

macrumors 65816
Original poster
Dec 29, 2010
1,343
0
Aartselaar // Antwerp // Belgium
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
 
If it's a certain system setting, why don't you mention exactly what it is instead of an unrelated example.
 
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.
 
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:
Code:
~/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:
Code:
/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:
Code:
/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:
Code:
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'.
 
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:

Code:
 defaults write com.apple.dock mcx-expose-disabled -bool true ;killall Dock
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.