Application that can be modified with admin name and password ...

Hi,

I want to modify by script an application that requires «admin» name and password to be modified. The app is scriptable. It belongs probably to «system» or «root». The application is «Power Manager Scripting». It is a hidden app located in «/usr/local/powermanager/bin».

How do I write a script to do that ?

Thanks for helping. Regards.

Robert

This is a reply to myself … that can be helpful to others. Since Power Manager (PM) is scriptable, it was easy to edit the app by scripting it. My problem was trying to edit a system preference pane that is locked (lockpad).

My way out of that problem what to work through the «user interface». I found a very interesting app for this purpose: Prefab UI Browser (follow this link: http://www.prefab.com/uibrowser). Very clever and well done app. I also got help from this forum in another thread.

This is the result of my work. I wrote the script to edit PM and then inserted handlers created to «unlock» and «lock» PM’s padlock. Here are the handlers:


on UnlockPowerManager()
	tell application "System Preferences"
		launch
		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
			if exists (button [i]"Pour modifier, cliquez sur le cadenas." of group 2 of window "Power Manager"[/i]) then
				click button [i]"Pour modifier, cliquez sur le cadenas." of group 2 of window "Power Manager"[/i]
				delay 0.5
				tell application "System Events"
					tell process "SecurityAgent"
						set value of text field 1 of group 1 of window 1 to adminName
						set value of text field 2 of group 1 of window 1 to adminPassword
						delay 0.5
						click button "OK" of group 2 of window "Authentification"
					end tell
				end tell
			end if
		end tell
	end tell
end UnlockPowerManager


on LockPowerManager()
	tell application "System Preferences"
		launch
		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 [i]"Pour empêcher les modifications, cliquez ici."[/i] of group 2 of window "Power Manager"
			delay 0.5
		end tell
	end tell
end LockPowerManager

As for retreiving securely your “adminName” and “admin Password”, here is another little handler that will do the job simply. It will pass the datas from a key of your Keychain app to your script:

on AdminDatas()
	tell application "Keychain Scripting"
		set adminKey to first generic key of current keychain where name is "nameOfYourAdminKey"
		set adminName to account of adminKey
		set adminPassword to password of adminKey
	end tell
end AdminDatas 

All tested on 10.4.11 and working … Insert those handlers where ever you need them and zip.

Please be patient when the «UnlockPowerManager» handler passes the «adminName» and «adminPassword» to «SecurityAgent». It is fully automatic, but a little bit long. Practice patience … It will be doubly rewarding. You will have to modify the name of the 2 buttons clicked by the handler. Mine are in french …

If you have any idea to make those handlers simpler, just drop a comment …

Hope this helps.

Robert