Applescript Help! Secuirty Settings

Discussion in 'Mac Programming' started by kodydoherty, Feb 14, 2012.

  1. macrumors newbie

    Joined:
    Feb 14, 2012
    #1
    I am trying to create a script to set some security settings on my MBP running Lion.

    I found this example using system events


    tell application "System Events"
    tell security preferences
    get properties
    set properties to {log out when inactive:false, automatic login:true, require password to unlock:false, log out when inactive interval:14, require password to wake:false}
    end tell

    end tell


    The script runs and asks for my admin password for each change. The issue is it does not actually change anything. I need this to change those preference but I don't understand why it is not working.
     
  2. macrumors 6502

    Joined:
    May 29, 2011
    Location:
    Littleton, Colorado, USA
    #2
    Not every object will let you set properties like that. Try setting them individually.
     
  3. r0k
    macrumors 68040

    r0k

    Joined:
    Mar 3, 2008
    Location:
    Detroit
    #3
    Try adding "with administrator privileges" at the end of the set properties line. This should prompt you for your admin password once and then do it all. Scroll all the way to the right in the code window below:

    Code:
    Tell application "System Events"
    	tell security preferences
    		get properties
    		set properties to {log out when inactive:false, automatic login:true, require password to unlock:false, log out when inactive interval:14, require password to wake:false} with administrator privileges
    	end tell
    	
    end tell
     
  4. thread starter macrumors newbie

    Joined:
    Feb 14, 2012
    #4
    r0k I tried your example in Lion and I got this error:
    Syntax Error

    A administrator:true can't go after this log out when inactive:false



    Also I tried all the properties one at a time and the script still did not work.
     
  5. r0k
    macrumors 68040

    r0k

    Joined:
    Mar 3, 2008
    Location:
    Detroit
    #5
    Here's another solution I found via google...

    Code:
    tell application "System Preferences"
      activate
    end tell
    
    tell application "System Events"
      tell process "System Preferences"
        click menu item "Sharing" of menu "View" of menu bar 1
        delay 2
        tell window "Sharing"
          click checkbox 1 of row 11 of table 1 of scroll area 1 of group 1
          delay 1
          if (exists sheet 1) then
            if (exists button "Turn AirPort On" of sheet 1) then
              click button "Turn AirPort On" of sheet 1
              delay 1
            end if
            click button "Start" of sheet 1
          end if
        end tell
      end tell
    end tell
    In this guy's example he is turning on and off the network but you could of course edit the script to open the security pref pane and click things there instead. I really like the way this guy's script checks to make sure things exist before clicking them. Hope this helps...
     
  6. macrumors 6502

    Joined:
    May 29, 2011
    Location:
    Littleton, Colorado, USA
    #6
    The with administrator privileges bit only applies to a do shell script command.

    How are you setting the individual properties? A statement such as set require password to wake to false (in the security preferences tell statement) works for me. Also note that if you are watching the prefpane for changes, you won't see them until you restart the System Preferences application again.
     
  7. thread starter macrumors newbie

    Joined:
    Feb 14, 2012
    #7
    Ok I got one to work

    Thanks for the help on the first one that worked great. The issue is if it requires my admin password it does not do anything. I type in my password and it just fails to change a properties. I have tried all of the settings I wanted to change with my example below and listed the ones that don't work. If the setting is locked is there a way just be able to type the password in and the change works?

    EX:

    Code:
    tell application "System Events"
    	tell security preferences
    		get properties
    		set require password to wake to true -- this works
    		set log out when inactive to true -- does not work
                    set automatic login to false -- does not work
                    set log out when inactive interval to 15 -- does not work
           
    	end tell
    end tell
     

Share This Page