Jump to content
Benzi

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.

Share this post


Link to post

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

Share this post


Link to post

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)?

Share this post


Link to post

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

Share this post


Link to post

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

Share this post


Link to post

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

Share this post


Link to post

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!  :)

Share this post


Link to post

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.

Share this post


Link to post

just tried the workflow and it does not recognize the new magic keyboard or magic trackpad2. I am also on OSX 10.11.

Edited by sstrool

Share this post


Link to post
# 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.

Share this post


Link to post
On 14/10/2016 at 7:11 PM, Zeno said:

It only works with the Magic Mouse and Magic Keyboard. Older versions do not work.

 

I have Magic Keyboard 2. Tried to debug it, but nothing appears when prompted.

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...