1. Welcome to the new MacRumors forums. See our announcement and read our FAQ

Editing System Prefs

Discussion in 'Mac Programming' started by jnoxx, Jun 17, 2011.

  1. macrumors 65816

    jnoxx

    #1
    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
     
  2. macrumors 68040

    #2
    If it's a certain system setting, why don't you mention exactly what it is instead of an unrelated example.
     
  3. Moderator

    robbieduncan

    Staff Member

    #3
    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.
     
  4. macrumors 603

    #4
    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'.
     
  5. macrumors 6502a

    #5
    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
     

Share This Page