PDA

View Full Version : Applescript Help! Secuirty Settings




kodydoherty
Feb 14, 2012, 10:24 PM
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.



Red Menace
Feb 21, 2012, 01:45 PM
Not every object will let you set properties like that. Try setting them individually.

r0k
Feb 21, 2012, 05:32 PM
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.

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:

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

kodydoherty
Feb 22, 2012, 03:11 AM
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.

r0k
Feb 22, 2012, 07:55 AM
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.

Here's another solution (http://www.macworld.com/article/157370/2011/01/applescriptsystempreferences.html) I found via google...

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...

Red Menace
Feb 22, 2012, 12:06 PM
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.

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.

kodydoherty
Feb 22, 2012, 12:27 PM
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:

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