Closed ha404 closed 7 years ago
Hello @ha404, thanks for the request.
Off the cuff, I believe this would not be too much trouble. I will keep you updated if the change makes it into a branch and also update you if it gets in the master branch. 🎆 👍
Similarly, I will try to post links I discover that assist in the solution and other build notes.
Amazing, I'd install this the instant it gets merged :)
@ha404, do you want this enabled by default or toggled with a button or checkbox? Im just thinking this out. It may exist on a separate branch when enabled by default.
I'm thinking:
Yeah, but if its paused it should cause the same battery consumption. I think disable the program completely unless plugged in with a launch agent monitoring the entire time to make that decision. The program itself, uses less than 10 percent of the cpu on average on my 2011 macbook pro.
also, just going to put this here: https://discussions.apple.com/thread/726938?tstart=0
Got my +1 haha.
In that case what will the default wallpaper be?
@ha404, default wallpaper defers back to your static wallpaper before aerial desktop installation.
Solution: single line terminal command.
ioreg -n AppleSmartBattery -w0 -x | grep CurrentCapacity | cut -d ' ' -f 19;ioreg -n AppleSmartBattery -w0 -x | grep MaxCapacity | cut -d ' ' -f 19;
source: @https://discussions.apple.com/thread/726938?tstart=0
take the two hex numbers from that command. divide the first by the second in google. and the result will be your battery percentage 😂
shoot, but how do I convert these hex numbers into decimal so that I can find the percentage, I dont really want to make a whole new file in order to find this solution. ...
https://stackoverflow.com/questions/13280131/hexadecimal-to-decimal-in-shell-script
hex value: 0x4a3
echo $((16#4a3))
works 😂
echo $((0x4a3))
also works! 😂
Bash scripting to solve hex conversion for me! 😸
but now we need to do division:
https://stackoverflow.com/questions/15015809/floating-point-results-in-bash-integer-division
bash for the win! 😂 😂 😹
numerator=$(echo $((0x4a3)));denominator=$(echo $((0x12a7))); echo $"(($numerator/$denominator))" | bc -l
@ha404, and I think this will give it an inline bash directive so it will work on zsh terminals!
https://stackoverflow.com/questions/11295659/is-there-such-a-thing-as-inline-bash-scripts
but I have not tested it!
sh -c 'numerator=$(echo $((0x4a3)));denominator=$(echo $((0x12a7))); echo $"(($numerator/$denominator))" | bc -l;'
tying it all together!
hex_num=$(ioreg -n AppleSmartBattery -w0 -x | grep CurrentCapacity | cut -d ' ' -f 19;); hex_denom=$(ioreg -n AppleSmartBattery -w0 -x | grep MaxCapacity | cut -d ' ' -f 19;); numerator=$(echo $(($hex_num)));denominator=$(echo $(($hex_denom))); echo $"(($numerator/$denominator))" | bc -l;
Okay so, that was the most insane and unreadable one line bash script I have ever written. The funny thing here is that the solution will probably be a single word key value in a launch agent that is the solution but this still turned out to be a fun exercise!
now it works in zsh too.
sh -c is an inline bash directive. :nerd_face:
sh -c 'hex_num=$(ioreg -n AppleSmartBattery -w0 -x | grep CurrentCapacity | cut -d " " -f 19;); hex_denom=$(ioreg -n AppleSmartBattery -w0 -x | grep MaxCapacity | cut -d " " -f 19;); numerator=$(echo $(($hex_num)));denominator=$(echo $(($hex_denom))); echo $"(($numerator/$denominator))" | bc -l;'
Shrunken down, without hex conversion.
sh -c 'numerator=$(ioreg -n AppleSmartBattery | grep CurrentCapacity | cut -d " " -f 19;);denominator=$(ioreg -n AppleSmartBattery | grep MaxCapacity | cut -d " " -f 19;); echo $"(($numerator/$denominator))" | bc -l;'
finally,
sh -c 'ioreg -l | grep ExternalConnected'
should tell if your macbook computer is charging or not.
https://developer.apple.com/documentation/kernel/iopmpowersource?language=objc
Man that's a lot of math...I imagined there was just a boolean somewhere haha
@ha404, I kind of jumped the gun with the math and scripting 😄 . basically this is the solution you were looking for:
sh -c 'ioreg -l | grep ExternalConnected'
or, better yet:
sh -c 'ioreg -l | grep IsCharging'
... returns "yes" if plugged in and "no" if not plugged in. try it out! 👍 So I could make that a zero and a one. Now delay on bringing this feature is my actually wanting to take the time to put it into the application. Four other features currently in the works on this application right now.
The large script displayed earlier is fairly advanced. It has a lot of bash magic! All of the code was discovered by others and the links I displayed led me to the code solutions.
I will probably start and finish this issue Saturday August 26, fingers crossed 🤞 .
@ha404, got it working on branch "add_battery_percentage" Its not currently released for non programmer installation. the code is not readable. I need to rewrite the code, I completed it as fast as I could.
Before I move it into master I want to have a discussion about it.
Look forward to your response/thoughts. @ha404
@ha404, sorry about the delay. The change is finally merged into master. And I am now creating a release for the change that will be accessible via the readme.
I will close the issue once the release is finished and integrated in the Readme 👍 😄
@MichaelDimmitt damn man you provide more support than some products/services I've paid for. Hats off to you, sir.
@ha404, thanks for the kind words!
If you enjoy the application, be sure to spread the word to others. 😄 ✌️
Let me know if you have any other Ideas by opening another issue. Or, feel free to provide feedback on this issue page. Hopefully you will be able to see the effects when your battery drains below '20%'
@ha404, Apologies, I discovered a bug. Today that I have resolved #26 . Now working like a charm.
once again I will close the issue when I update the release. 😐 just waiting for battery to go below 20 percent for verification purposes. curr, 23 percent.
Works! plugging back in had three sec lag on my machine. but Aces. zip file and/or normal clone both working appropriately!
I think that'd be an awesome feature for those who are concerned about even the smallest power consumption on battery.