MBS IOPMAssertionMBS.AssertionsByProcess Objects

Hello,
I’m trying to determine all of the current power assertions on macOS using the MBS IOPMAssertionMBS.AssertionsByProcess shared method. I have added the plugins (MBS Xojo Encryption Plugin.xojo_plugin; MBS Xojo MacOSX Plugin.xojo_plugin; MBS Xojo MacOSXCF Plugin.xojo_plugin; MBS Xojo Main Plugin.xojo_plugin) to my Xojo Plugins folder. After registering them I use the following in the console App.run to call my method to check assertions:

dim run as Boolean = true while run dim PowerAssertions as Dictionary PowerAssertions = App.CurrentAssertionsDetails() wend
This gives me a loop to check the assertions while I do things on the mac, like starting a package install. The method contains:

[code]// Dictionary for all assertions
dim CurrentPowerAssertions as new Dictionary
// Dict for current assertions
dim ActivePowerAssertions as new Dictionary
// Key and Value Placeholders
dim DictKey as string
dim DictValues() as Dictionary
// Gather all assertions
CurrentPowerAssertions=IOPMAssertionMBS.AssertionsByProcess

// Step through all assertions starting with i = 0
dim i as Integer

// Check each assertion for active ones
for i = 0 to CurrentPowerAssertions.Count -1
// Gets process ID for each assertion
DictKey=CurrentPowerAssertions.Key(i)
// Object array? What is this thing?
dim assertionVal() as Object = CurrentPowerAssertions.Value(CurrentPowerAssertions.Key(i))

// Try to look at each dictionary in Object Array, fails…
// Returns Type mismatch error. Expected class Dictionary, but got Object
'For each j as Dictionary in assertionVal

// Cast as Object for each assertionVal, but can’t do anything with it?
// Looks like Dictionary, but I can’t get any key/values
For each j as Object in assertionVal
// Type “Object” has no member named “key”
'dim newKey as string = j.key(i)
// Get details for each assertion for each process?
next
next
// Return the assertions we care about later
return ActivePowerAssertions[/code]

As far as I can tell, the IOPMAssertionMBS.AssertionsByProcess should return a dictionary with the process number as the key and an array of values. The arrays contain dictionaries of assertions, but seem to be stored as an Object array? I’m unsure how to retrieve each of the dictionaries of the object array to inspect their values, like “AssertType” or “Process Name”.

When running this is what I see for CurrentAssertions:

Assertion Values contain:

It looks like “j” is a dictionary but I can’t seem to get any key/values:

Here are the contents of “j”:

in the loop you can put:

dim dic as Dictionary = Dictionary(j) Break

this would cast the object to dictionary, so you can work with that.

Better may be to use Variant for j to avoid casts:

For each j as variant in assertionVal // Type "Object" has no member named "key" dim dic as Dictionary = j Break // Get details for each assertion for each process? next

That’s it! Really appreciate the info, Christian! Thanks!