Xojo Conferences

Platforms to show: All Mac Windows Linux Cross-Platform

FAQ.How to check if Macbook runs on battery or AC power?
Answer: Please use our IOPowerSourcesMBS class like this:
Function PowerSourceState() as Integer
dim p as new IOPowerSourcesMBS

// check all power sources
dim u as Integer = p.Count-1
for i as Integer = 0 to u
dim d as CFDictionaryMBS = p.Item(i)
if d<> nil then
// check if they have a power source state key:
dim o as CFObjectMBS = d.Value(NewCFStringMBS("Power Source State"))
if o isa CFStringMBS then
dim s as string = CFStringMBS(o).str

'MsgBox s

if s = "AC Power" then
Return 1
elseif s = "Battery Power" then
Return 2
end if
end if
end if
Return 0 // unknown
End Function
Notes: If you want to check the CFDictionaryMBS content, simply use a line like "dim x as dictionary = d.dictionary" and check the contents in the debugger.

Feedback, Comments & Corrections

MBS FileMaker Plugins