Jump to content

Battery2 - Battery levels of laptop battery, Apple keyboard, trackpad and mouse


Recommended Posts

@Benzi is there a way your workflow notifies me via Growl when my battery energy level is at X%?

 

I use one other battery workflow + bartender -> I do not get any warning message.

 

No, unfortunately not at the moment.

 

This should be possible though, with some sort of background app/daemon that subscribes to battery level notifications via OS X; sadly, I don't have enough know how to implement something like that yet. (maybe if I get some free time...) 

Link to comment

Great. Thanks for you work and sharing.

 

I use the Logitech Bluetooth Easy-Switch Keyboard K811. Do you think there's a way to get the battery status of other devices than from Apple?

Also I use the Phone Amego App together with the great Uni Call Workflow from guiguan.

Phone Amego can show the Battery Status of the connected iPhones. You see a chance for that?

 

Once again, thanks for you work and ideas. Really appreciate.  

 

 

Bildschirmfoto%202013-11-02%20um%2013.10

Link to comment

I never know how to feel about writing a background daemon for these sorts of things as Alfred workflows. The point of Alfred is to invoke things manually. Writing a daemon is really more of writing an application, and so packaging it as a Workflow is possible, but, again, I'm not sure if it should happen.

 

Although, if you do want to make it happen, then you'd need to do a few things: look at this stackoverflow discussion. That would make it so that it really isn't a daemon that runs all the time, but, instead, it would be a script invoked at certain times. For the workflow, you'd probably want to put in an "install" command that would copy the relevant file that is packaged with the Workflow to the relevant place (if you're using launchctl). If you're using Cron, then you'd want to write an entry to the crontab, but you'd also want to make sure that it doesn't add in the line multiple times because, then, the command would be run too often. I'd recommend invoking the install with an applescript so that you can put in the line "with administrator permissions" or whatever it is exactly. Otherwise, you'd have to use 'sudo'.

 

If you want to run it as a daemon, what you can do is to write a bash script that runs the script and receives the output and then sleeps for however long you want it to sleep. When you do this, make sure that you 'disown' the process. Otherwise, an Alfred thread will be continually running, which will interfere with Alfred's normal functioning. Include a command to kill the daemon. Also, make sure that the daemon isn't launched multiple times (you can use 'ps aux|grep <daemon name>|grep -v grep'; then, if there is any output, it'd mean that the daemon is running and not to launch it again. To kill it, instead of finding the process, you could just invoke the "killall" command in which you'd just send "killall <processname>". This setup would make it so that Alfred would have to launch it and kill it. So, it won't be started each time you reboot your computer. If you want to do that, you'll have to include it in the start-up items (which I think is a bit harder with Mavericks). I'd also recommend putting in a "status" command with Alfred to see if the daemon is running.

 

For the notifications, you have a few options: you could write an applescript that will send a dialog whenever things are low. However, this will be intrusive. You could also invoke growl to send the messages (this requires a tiny bit of configuration with growl and you can't assume growl is installed). The third way would be to package the ruby gem 'terminal-notifier' which creates regular notifications. You'd just invoke the script and make the notification sticky.

 

So, with this approach, the Alfredworkflow would just install and manage the daemon or cron job. You'd also want to put in an uninstall command (especially if you're using cron, and you'd want to have an automatic uninstallation feature if the workflow is deleted). But, again, I'm uneasy about using Alfred to write daemons. Temporary ones are fine (think of a timer that works similarly to what I've outlined above, but one that stops itself after a certain amount of time), but daemons that become a perennial part of your system just seem like something that is entirely different than Alfred.

 

Lastly, if you do write something that includes a daemon that runs permanently, then I believe that you should make it clear and explain how the daemon works when you release the Workflow. That way people know what you're putting on their computer.

 

--Shawn

Link to comment

Hi Benzi - would it be possible to amend this so that when you select the computer battery, you get all the info from your first battery workflow (cycle count , health etc)?

 

That is possible; although, at the moment, since both workflows have the same keyword "battery", I'd have to change both workflows. Keeping the old one as is, I'll modify this version to include those battery details (cycle count and health mainly). I'll share an updated version soon

Link to comment

Great. Thanks for you work and sharing.

 

I use the Logitech Bluetooth Easy-Switch Keyboard K811. Do you think there's a way to get the battery status of other devices than from Apple?

Also I use the Phone Amego App together with the great Uni Call Workflow from guiguan.

Phone Amego can show the Battery Status of the connected iPhones. You see a chance for that?

 

Once again, thanks for you work and ideas. Really appreciate.  

 

 

That keyboards looks sweet! Regarding getting the battery status I'm not sure. Even if there is some way to get those details technically, I'd have no way to check and test it out because I don't own those devices. So this may not be possible at the moment.

 

The iPhone status sounds like a good idea, I'll dig around and see if I can come up with something. Again, no promises!  :)

Link to comment

Hi Benzi - would it be possible to amend this so that when you select the computer battery, you get all the info from your first battery workflow (cycle count , health etc)?

 

As a start, I have updated this workflow to display more information as is - so no need for the other workflow. I'll see what more I can add to this, meantime though go ahead and download the latest version and try it out.

Link to comment
  • 2 years later...
  • 3 weeks later...
  • 9 months later...
  • 4 weeks later...
# mouse
#MousePercent=`ioreg -c AppleDeviceManagementHIDEventService | grep 'Magic Mouse' -A6 | grep BatteryPercent | sed 's/[a-z,A-Z, ,|,\",=]//g' | tail -1 | awk '{print $1}'`
MousePercent=`ioreg -n "BNBMouseDevice" | grep BatteryPercent | sed 's/[a-z,A-Z, ,|,\",=]//g' | tail -1 | awk '{print $1}'`

helped me on the latest macOS.

Link to comment
  • 4 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...