BATTERY MONITOR/METER FOR MACBOOK
Hello, anyone kind enough to tell me how to create a simple battery monitor in max for live.
I have seen clock, but haven't found any way to make a big battery monitor to let me know the remainder of life my laptop has. I am using a Mac. Thanks.
You need shell object.
than send it message :
pmset -g batt
than see how to parse the output.
Depending on shell version it will output all in one symbol or not.
To start with, connect shell output to print.
You'll get something like :
"Currently drawing from 'AC Power'" " -InternalBattery-0 100%; charged; 0:00 remaining"
" Detailed failures: \"Externally Indicated Failure\", \"Safety Over-Voltage\", \"Cell Imbalance\", \"Discharge FET\""
Thank you so much, you are awesome. I downloaded this shell object, https://github.com/jeremybernstein/shell/releases/tag/1.0b2
followed your instructions and was able to print this:
"Now drawing from 'AC Power' "
" -InternalBattery-0 (id=7733347) 100%; charged; 0:00 remaining present: true"
Now parsing the output is where I am stuck/lost.
Can you shed some light please?
I would like to have a button be On or Off depending on drawing power state AC Power or Battery. And also I would like to have maybe a slider represent percentage of battery charge.
" -InternalBattery-0 (id=7733347) 100%; charged; 0:00 remaining present: true"
count the symbol until you are at the info you want using [atoi], then collect the outputs no. 35, 36, 37 into a list, then [sprintf %s%s%s]
Thanks Roman, I Kind of got it working but when a big Ableton set is loaded the message: pmset -g batt
seems to be very system intensiveand my audio halts for a bit. Is there any other command that you guys know about that might not make the CPU think as hard?
There is nothing else max can use to get the battery state.
Not that I know.
In Max, using shell with that command causes absolutely no
problems or CPU load.
Being no fan of Ableton at all, can't help You with that problem.
How often do You trigger the message ?
One option could be to make minimal Max standalone
sending battery state to Live as UDP message.
I am using older version of shell and output might be a bit different.
Here is a patch parsing % of charge and charging/discharging state,
which indicates if AC Power is connected.
for classic macos there was an external which showed the CPU temperature.
not even macos itself did this out of the box. :)
Thank you guys for your help. SOURCE AUDIO, thank you for that patch parsing the output, I was able to get it working exactly how I wanted... but is useless, because for some reason running any osascript from Ableton, is halting everything else, like audio being played and graphics on mixer. The way I see it, is like maybe it sets the priority to high for running the command or something. I was triggering the message manually for testing but I tried using the metro object like your patch but is the same.
Now, weird thing is, that when I have the maxforlive editor opened, and trigger the message it doesn't produce a CPU spike, but when I save and run it from Ableton, it is basically useless.
Again this is only with a big Live set. If the set/project is empty it will run with no problem!
SOURCE AUDIO you mentioned that you are using an older version of shell... do you think the shell version I am using might be the issue? Where can I download the version you're using?
If I cannot get this working I'll try running an AppleScript. I started messing with that, but haven't yet figured out how to make the AppleScript send midi or communicate somehow with maxforlive.
I read about a tap.applescript object, but I haven't been able to find it for download anywhere.
Thanks again guys
i am just guessing here: did you try yet to [deferlow] the message you send to [shell]?
normally a background process shouldnt disturb the max4live runtime or live´s timing at all.
when you type "sudo bring me a sandwich" in a unix console an audio app will normally also to continue to do its stuff without hickups.
Apple script ???
I don't know of midi sending apple script by itself.
You have to use pmset to get battery status.
So it has to be shell script in a loop, or remotely triggered.
One option would be sending udp data using for example netcat.
It would all be rather complicated if You have no knowledge of that stuff.
So I would say make max standalone to do that for You.
I would prefer udp over midi.
-----
if You want to try apple script way,
than here at least this:
echo 88 | nc -u -w 0 127.0.0.1 6666
this is netcat raw UDP message, sending 88 to UDP port 6666.
To decipher that You need sadam sadam.udpClient set to localhost
and src_port 6666
connect left outlet to itoa .
udpreceive max object can't cope with that.
So at the end You would need to get battery status, extract that few
needed infos and send them using nc (netcat) UDP packet to live.
Here is shell version I am using, from 2017, I don't think it would make any¨difference
to Live :
As Roman suggested defer or deferlow might help, but
it is really strange that scripting which has nothing to do
with audio processing creates such hickups in Live.
P.S.
here is applescript getting battery status and sending
UDP messages.
You need sadam library, in fact only sadam udp client
http://www.sadam.hu/download/sadamlib.zip
------
here is the code :
---------------------
repeat
set battery to (do shell script "pmset -g batt | awk -F '[[:blank:]]+|;' 'NR==2 {print $3 $4, $5 $6, $7, $8}'")
do shell script "echo " & battery & " | nc -u -w 0 127.0.0.1 6666"
delay 2
end repeat
--comments
-- continious loop
-- $3 $4 $5 etc are list items to output, comma adds space
-- delay time in seconds between repetitions
-- 127.0.0.1 6666 is localhost and UDP port 6666
-- nc is short for netcat
--------------------
Paste it in script editor, save as Application.