Because LC can't do two things at once.

mikedoub at gmail.com mikedoub at gmail.com
Mon Mar 2 10:20:54 EST 2015


It will be added when the linux part is sorted out. :)

Mike

  Original Message  
From: Mike Kerner
Sent: Monday, March 2, 2015 9:35 AM
To: How to use LiveCode
Reply To: How to use LiveCode
Subject: Re: Because LC can't do two things at once.

that doesn't suck and ought to be in the masterLibrary, or whatever it's
called.

On Sun, Mar 1, 2015 at 1:04 PM, Peter M. Brigham <pmbrig at gmail.com> wrote:

> Just closing the loop on this one (the power source of a laptop). (Calling
> Richard Gaskin re the Linux case...)
>
> -- Peter
>
> Peter M. Brigham
> pmbrig at gmail.com
> http://home.comcast.net/~pmbrig
>
> ---------
>
> function getPowerSource
> -- returns the current power source for a laptop
> -- "AC" or "Battery"
> -- requires caseSwitch()
> switch the platform
> case "MacOS"
> -- thanks to Martin Koob, use-LC list
> put shell ("pmset -g batt") into tSource
> -- 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 tSource
> break
> case "Win32"
> -- thanks to Bob Sneidar, use-LC list
> -- someone with a Windows machine should test this case
> put shell("WMIC Path Win32_Battery GetAvailability") into tSource
> -- Line 3 will contain 2 if the battery is charging, 3 if running
> on battery
> put line 3 of tSource into tStatus
> return caseSwitch(tStatus,"3=Battery","*=AC")
> break
> default
> -- Linux awaiting Richard Gaskin...
> end switch
> end getPowerSource
>
> function caseSwitch
> -- does a quick inline switch/case
> -- param 1 is checkValue
> -- params 2+ are in the form matchValue(s)>=<returnValue
> -- separate multiple matcheValues with commas
> -- and enclose each matchValue=returnValue pair in quotes
> -- if checkValue matches one or more items in matchValue(s),
> -- returns returnValue
> -- note that checkValue should NOT be enclosed in quotes
> -- use a matchValue of "*" to specify a default value,
> -- to be returned if no matches found in the list
> -- if the default is "*=*" then no match returns the original
> <checkValue>
> -- if no match and no default value specified, then returns empty
> -- usage:
> -- put caseSwitch(len(tZip),"5=zip","10=zip+4","*=not a zip code") \
> -- into zipCodeType
> -- from Ken Ray, use-LC list, originally named stsSwitch()
>
> put param(1) into tCheckValue
> set the itemDel to "="
> put "" into tDefault
> repeat with x = 2 to the paramCount
> put param(x) into tCheck
> put item 1 of tCheck into tMatch
> put item 2 of tCheck into tRetVal
> replace "," with "=" in tMatch
> if tCheckValue is among the items of tMatch then return tRetVal
> if tMatch = "*" then
> if tRetVal = "*" then
> put tCheckValue into tDefault
> else
> put tRetVal into tDefault
> end if
> end if
> end repeat
> return tDefault
> end caseSwitch
>
> ----------
>
> On Feb 21, 2015, at 2:59 AM, Richard Gaskin wrote:
>
> > Peter M. Brigham wrote:
> >
> >> Just out of curiosity, how *would* you do this via shell call or
> >> the equivalent on a Windows laptop?
> >
> > Good question.
> >
> > Thanks to the beautiful simplicity of the Linux /proc directory I was
> able to find:
> >
> > cat /proc/acpi/battery/BAT1/state
> >
> > The "charging state" field there will contain "charging" or
> "discharging".
> >
> > Now if we can turn up a Win command line solution I'll write a handler
> for this that'll make it convenient to get this info on all three platforms.
> >
> > Martin, thanks for handling the Mac side - nice work.
> >
> >
> >> On Feb 20, 2015, at 11:19 AM, Martin Koob wrote:
> >>
> >>> Hi Richard
> >>>
> >>> I noticed in your bug report was for Mac so till that enhancement gets
> >>> implemented you could use this.
> >>>
> >>> function powerStatus
> >>> put shell ("pmset -g batt") into tPowerStatus
> >>> put matchtext(tPowerStatus, "'([^']*)",tPowerSource) into tSuccess
> >>> return tPowerSource
> >>> end powerStatus
> >
> >
> >
> > --
> > Richard Gaskin
> > Fourth World Systems
> > Software Design and Development for Desktop, Mobile, and Web
> > ____________________________________________________________
> > Ambassador at FourthWorld.com http://www.FourthWorld.com
> >
> > _______________________________________________
> > use-livecode mailing list
> > use-livecode at lists.runrev.com
> > Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> > http://lists.runrev.com/mailman/listinfo/use-livecode
>
>
> _______________________________________________
> use-livecode mailing list
> use-livecode at lists.runrev.com
> Please visit this url to subscribe, unsubscribe and manage your
> subscription preferences:
> http://lists.runrev.com/mailman/listinfo/use-livecode
>



-- 
On the first day, God created the heavens and the Earth
On the second day, God created the oceans.
On the third day, God put the animals on hold for a few hours,
and did a little diving.
And God said, "This is good."
_______________________________________________
use-livecode mailing list
use-livecode at lists.runrev.com
Please visit this url to subscribe, unsubscribe and manage your subscription preferences:
http://lists.runrev.com/mailman/listinfo/use-livecode




More information about the Use-livecode mailing list