Is there a way to unlock the system preferences with a script or a shell script ? By security, I would use Keychain scripting to acess admin name and password.
Your are obvioulsy everywhere in this forum. To AppleScripting, I consider my self an adventurous novice. To shell and GUI scripting I know nothing except copying and pasting scripts.
So with your generous help, I would consider looking into shell and GUI scripting.
Do I understand that it is also possible with shell scripting ? Can you point a ressource to start. Funny enough, I didn’t find anything in this forum.
As GUI and shell scripting must be very specified, because it depends on the purpose,
it would be easier to come to know what you are going to accomplish
I am scripting Power Manager (PM). PM is an system preference pane that can create/modify/delete events to put the computer to sleep or awake it. It is a very interesting tool.
I wrote a script that adds/modifies/deletes events by scripting the engine behind PM. This engine is called «Power Manager Scripting» (PMS). This engine is hidden. It is locked and needs admin name and password before accepting modifications to events.
I tried to find a way to unlock PMS by talking to PM’s developper, but couldn’t yet find a way to do it. Because unlocking System Preferences seems to unlock all locked preferences (Network, Startup, Date and time, etc …), I want to script that unlocking process in order for my modifications to be authorized.
I already have the Keychain Scripting part, that will retrieve admin name and password and pass it to the other part of my script, this thread is for. Here is a handler for the Keychain part:
on adminDatas()
tell application "Keychain Scripting"
set admKey to first generic key of current keychain where name is "myKeySessionOrWhatever"
set admName to account of admKey
set admPassword to password of admKey
end tell
end adminDatas
It’s quite strange, I downloaded PM to test it and I’m able to use all scripts without any authentication.
Do you run all the things in a managed account without admin privileges?
Anyway, here’s a script, which opens the PM-PrefPane and unlocks it, you have to add your routine to retrieve the password
tell application "System Preferences"
activate
reveal anchor "Options" of pane id "uk.co.dssw.powermanager.preferencepane"
end tell
tell application "System Events"
tell process "System Preferences"
repeat until exists window "Power Manager"
delay 0.5
end repeat
click button "Click the lock to make changes." of group 2 of window "Power Manager"
end tell
repeat until exists window 1 of process "SecurityAgent"
delay 0.5
end repeat
tell process "SecurityAgent"
tell window 1
tell scroll area 1 of group 1
set value of text field 1 to "user"
set value of text field 2 to "pass"
end tell
click button "OK" of group 2
end tell
end tell
end tell
If you can add, modify or delete events in PM without authentication, as far as I know, it is because your system preferences’s padlock is unlock in some other system preference. Unlocking the padlock in any system preference unlocks the padlock of all system preferences.
As for your script, thank you. I will give it a try and post the result in this forum. Giving all that time to help us is very generous. Hope you enjoy it yourself.
I checked and adminDatas returns the admName and admPassword correctly to the script. I get an error when executing from the ScriptEditor. The authentification window opens but no name and password is passed to the input fields. Then in the background the Script Editor window opens an error message: System events error: «NSReceiverEvaluationScriptError:4»
I didn’t find a solution to the problem of the GUI script. Where can I find information on the meaning and use of the GUI vocabulary ? Maybe that could help fix that in my Tiger environment.
Sorry, I run Leopard on my machine and it is impossible to test a GUI script for Tiger on a Leopard environment, because detecting the UI elements is a lot of trial and error.
But you do it by yourself using a tool like UIElementInspector
i have customized modifier keys in system preferences>>Keyboard and mouse>> keyboard.
and i frequently need to toggle between the customized ones and default ones. so i decided to use
UI element inspector. when i press “keyboard and mouse” in sys preferences window i get this
<AXApplication: “System Preferences”>
<AXWindow: “System Preferences”>
I have gotten a little bit further. Modifying StefanK’s code to adat it to Tiger with code found in another MacScripter thread …
tell application "System Preferences"
activate
reveal anchor "Options" of pane id "uk.co.dssw.powermanager.preferencepane"
end tell
tell application "System Events"
tell process "System Preferences"
repeat until exists window "Power Manager"
delay 0.5
end repeat
click button "Pour modifier, cliquez sur le cadenas." of group 2 of window "Power Manager"
end tell
repeat until exists window 1 of process "SecurityAgent"
delay 0.5
my authenticate_changes()
delay 4
keystroke tab
keystroke (ASCII character of 31)
end repeat
end tell
on authenticate_changes()
tell application "System Events" to tell window "Authentification" of process "SecurityAgent"
tell group 1
set value of text field 1 to "myAdminName"
set value of text field 2 to "myAdminPassword"
end tell
click button "OK" of group 2
end tell
end authenticate_changes
The script stops at the «Authentification» window. It does not type the adminName and adminPassword in the textfield. It just waits … Maybe there is «type text» command to add or something like that …
Keep hope and try this (on my int’l system it works):
tell application "System Preferences"
activate
reveal anchor "Options" of pane id "uk.co.dssw.powermanager.preferencepane"
end tell
tell application "System Events"
tell process "System Preferences"
repeat until exists window "Power Manager"
delay 0.5
end repeat
click button "Click the lock to make changes." of group 1 of window "Power Manager"
end tell
delay 0.5
repeat until not (exists window 1 of process "SecurityAgent")
delay 0.5
my authenticate_changes()
delay 4
keystroke tab
keystroke (ASCII character of 31)
end repeat
end tell
on authenticate_changes()
tell application "System Events" to tell window "Authentification" of process "SecurityAgent"
keystroke "yourpass"
keystroke tab
keystroke "yourID"
keystroke return
end tell
end authenticate_changes
Sorry I am using Leopard but the principle is the same as in Tiger.
Be sure that Security Agent’s Auth window is upfront and do a keystroke tab until your password field is selected.
Enter password, tab again, enter name, enter return and off you go.