Aerial-Desktop / Aerial_Desktop

Macintosh Application installs Aerial ScreenSaver and sets as a Desktop Background. 🚀 🎩
50 stars 4 forks source link

allow only when power is connected #16

Closed ha404 closed 7 years ago

ha404 commented 7 years ago

I think that'd be an awesome feature for those who are concerned about even the smallest power consumption on battery.

MichaelDimmitt commented 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.

ha404 commented 7 years ago

Amazing, I'd install this the instant it gets merged :)

MichaelDimmitt commented 7 years ago

@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.

ha404 commented 7 years ago

I'm thinking:

  1. Have it always start at a random scene
  2. If plugged in: Play video
  3. Else: Remain paused
MichaelDimmitt commented 7 years ago

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

ha404 commented 7 years ago

Got my +1 haha.

In that case what will the default wallpaper be?

MichaelDimmitt commented 7 years ago

@ha404, default wallpaper defers back to your static wallpaper before aerial desktop installation.

MichaelDimmitt commented 7 years ago

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

MichaelDimmitt commented 7 years ago

@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;'

MichaelDimmitt commented 7 years ago

It actually tells you your battery percentage

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!

MichaelDimmitt commented 7 years ago

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;'

MichaelDimmitt commented 7 years ago

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;'

MichaelDimmitt commented 7 years ago

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

ha404 commented 7 years ago

Man that's a lot of math...I imagined there was just a boolean somewhere haha

MichaelDimmitt commented 7 years ago

@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.

MichaelDimmitt commented 7 years ago

I will probably start and finish this issue Saturday August 26, fingers crossed 🤞 .

MichaelDimmitt commented 7 years ago

@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.

  1. Program currently monitors every five seconds if your battery percentage is above 20 percent
    or if it is charging.
  2. Program can easily be modified to just run when charging and not work when not charging.
  3. The way the program is currently set up the battery percentage can be customized to any percentage level. For instance you might decide to monitor if battery percentage is above 90 percent otherwise halt the program.
  4. Currently I removed all notifications. It does what has been discussed automatically without you having to worry about it. Apologies for the grammar on this comment. Checking out for the day. Ill come back and edit it for clarity tomorrow.

Look forward to your response/thoughts. @ha404

MichaelDimmitt commented 7 years ago

@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.

24

I will close the issue once the release is finished and integrated in the Readme 👍 😄

ha404 commented 7 years ago

@MichaelDimmitt damn man you provide more support than some products/services I've paid for. Hats off to you, sir.

MichaelDimmitt commented 7 years ago

@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%'

MichaelDimmitt commented 7 years ago

@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.

MichaelDimmitt commented 7 years ago

Works! plugging back in had three sec lag on my machine. but Aces. zip file and/or normal clone both working appropriately!