on 3/3/15, I wrote: > OK, as usual, I find some tweaks *after* I hit the send button. I changed > caseSwitch() so it handles the case of an empty tCheckValue, allowing > getPowerSource() to report "no battery" if getting the URL returns empty. > The expansion of caseSwitch() is useful in and of itself….
Sigh. Some typos in the handler I sent -- I was changing variable names and didn't change everything. Here is the (hopefully) correct and testable handler. It never fails -- I am learning that if I want to debug something, all I have to do is send it off to this list and I'll immediately find the errors, *after* I hit send. -- Peter Peter M. Brigham pmb...@gmail.com http://home.comcast.net/~pmbrig ---------- function getPowerSource -- returns the current power source for a laptop -- "AC" or "Battery" -- or "no battery" if there is no battery (Unix) -- requires caseSwitch() switch the platform case "MacOS" -- thanks to Martin Koob, use-LC list put shell ("pmset -g batt") into tStatus -- returns something like: -- Currently drawing from 'AC Power' -- -InternalBattery-0 99%; finishing charge; 0:00 remaining return char 2 to -1 of word -2 of line 1 of tStatus break case "Win32" -- thanks to Bob Sneidar, use-LC list put shell("WMIC Path Win32_Battery GetAvailability") into tStatus -- Line 3 will contain 2 if the battery is charging, 3 if running on battery put line 3 of tStatus into tStatus return caseSwitch(tStatus,"3=Battery","*=AC") break default -- Unix, thanks to Richard Gaskin, use-LC list put url "/sys/class/power_supply/BAT0/" into tStatus if tStatus = empty then put url "/sys/class/power_supply/BAT1/" into tStatus put word 1 of tStatus into tStatus return caseSwitch(tStatus,"discharging=Battery","charging,full=AC",\ "=no battery","*=*") -- if tStatus = empty, returns "no battery", else if tStatus is non-standard, -- just returns whatever "/sys/class/power_supply/BATx/" reports end switch end getPowerSource _______________________________________________ use-livecode mailing list use-livecode@lists.runrev.com Please visit this url to subscribe, unsubscribe and manage your subscription preferences: http://lists.runrev.com/mailman/listinfo/use-livecode