Sync Indigo's and Power Manager's events list ...

Hi,

Since Indigo and Power manager are fully scriptable apps, I want to synchronize Indigo’s TimeDate events with PM’s event list.

My idea is to list Indigo’s event for the day, every day at midnight. Then I would check PM’s event list and «delete previous and add new» or »add new» for any event with corresponding/missing name in Indigo’s list. This way PM’s events would be synchronized with changes in Indigo’s events, after a manual modification or because of the modification in the «Sunrise/Sunset» time.

How can I create a list of Indigo’s and PM’s events ?
How can I create a resulting list in PM that would serve as the database to generate the new events in PM ?

A little bit tricky for me. All new scripting vocabulary … :rolleyes::rolleyes::rolleyes:

Any ressources to suggest ?

Thanks for reading.

Robert Lespérance

Worked that problem out. Because my Indigo software is running on a remote non-passworded user (to open after a crash or power failure), I needed to update Power Manager (PM) comparing Indigo’s events on my remote user. Here is the resulting script and handlers. I called it «Update Power Manager (remote)»:

---Define remote user number
property remoteUserID : "yourRemoteUserNumber"

-- You can define a prefix to be added to events created in PM
property IndigoEventPrefixe : ""

-- Handler to retrieve admin name and passworh
property adminName : ""
property adminPassword : ""
AdminDatas()

-- Defines the remote user name
set {host name:hostName} to (system info)
set remoteMachine to "eppc://" & adminName & ":" & adminPassword & "@" & hostName & "/?uid=" & remoteUserID
set vUpdate to 0

-- Handler to unlock PM
UnlockPowerManager()

---In Indigo, check every events ...
using terms from application "Indigo"
	tell application "Indigo" of machine remoteMachine
		repeat with i in time date actions
			if i is enabled then
				if name of i does not contain "internal" then
					
					---Copy the name and the next trigger time of the event in Indigo.
					set EventName to name of i
					set NextTrigger to (next trigger time) of i
					
					-- If any event with that name exists in PM, delete it and replace it by a new one that will execute 1 minute before the Indigo event.
					tell application "Power Manager Scripting"
						tell scheduler
							if exists (PMEvent (IndigoEventPrefixe & EventName)) then
								add event {enabled:true, unique id:EventName, name:IndigoEventPrefixe & EventName, trigger:{type class:once, date:((NextTrigger) - 60)}, action:{type class:start up or wake}}
								
								-- If there is no event with the name of the Indigo event create a new one as above.
							else
								tell application "Power Manager Scripting"
									tell scheduler
										add event {enabled:true, unique id:EventName, name:IndigoEventPrefixe & EventName, trigger:{type class:once, date:((NextTrigger) - 60)}, action:{type class:start up or wake}}
									end tell
								end tell
							end if
						end tell
					end tell
				end if
			end if
		end repeat
	end tell
end using terms from

-- Lock Power Manager
LockPowerManager()

-- Bring the "Finder" is foreground
ClickDockItem("Finder")


--- Handlers ----------------------------------------------------------------------

-- Retrieve admin datas from Keychain
on AdminDatas()
	tell application "Keychain Scripting"
		set adminKey to first generic key of current keychain where name is "yourAdminKeyFromKeychain"
		set adminName to account of adminKey
		set adminPassword to password of adminKey
	end tell
end AdminDatas

-- Unlocks Power Manager
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 "Pour modifier, cliquez sur le cadenas." of group 2 of window "Power Manager") then
				click button "Pour modifier, cliquez sur le cadenas." of group 2 of window "Power Manager"
				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


-- Locks Power Manager
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 "Pour empêcher les modifications, cliquez ici." of group 2 of window "Power Manager"
			delay 0.5
		end tell
	end tell
end LockPowerManager

-- Click a dock item to bring it in foreground
on ClickDockItem(theItem)
	launch application "Dock"
	tell application "System Events"
		tell process "Dock"
			click UI element theItem of list 1
		end tell
	end tell
end ClickDockItem

Hope this helps.

Robert

Hi Robert,

GUI scripting often depends on the system language, in your case the script works only in a french system.
To make it independent from the language, you can also refer to UI elements by index

Hi StefanK,

Good point … Didn’t think about that ! I will update that as soon as possible.

Regards

Robert