Thursday, October 17, 2013

Magic Mouse Battery Geeklet

This Geeklet shows the currently left Battery stats for your Magic Mouse on the Desktop, the final result will look like this:


Difficulty: Medium



To achieve this you first need the following PNG Images:

The Background Image:

And the fill bar for the Indicator:

Save both Images on your Mac, the Path for the Fill.png is needed for later Script Editing

1. Drag an Image Geeklet and link it with the Background Image
2. Drag anther Image Geeklet, but now its important to name it, in the Geeklet settings, at the top, go to Name field and call it:

batt

3. Drag a Script Geeklet and enter the script Editor, paste the foööowing Code inside it and save, set the Refresh to e.g. every 30 minutes, so 60*30 will do the Math (hint: 1800 ^^)

kbatt=`ioreg -c AppleBluetoothHIDKeyboard | grep BatteryPercent | awk -F"=" {'print $2'}` &&
if [ ${#kbatt} -gt 0 ]; then echo "Bluetooth Keyboard: $kbatt%"; fi &&
tbatt=`ioreg -c BNBTrackpadDevice | grep BatteryPercent | tail -1 | awk -F"=" {'print $2'}` &&
if [ ${#tbatt} -gt 0 ]; then echo "Magic Trackpad Battery: $tbatt%"; fi && 
mbatt=`ioreg -c BNBMouseDevice | grep BatteryPercent | tail -1 | awk -F"=" {'print $2'}` &&
if [ ${#mbatt} -gt 0 ]; then echo "$mbatt %"; fi;

wait ${!}

sips -z 21 ${mbatt} /Users/Uername/psth_to_file/fill.png --out /Users/Username/path_to_file/fill_new.png 2>/dev/null

wait ${!}

osascript<<END 
 tell application "GeekTool Helper"
  set Position to first item of (geeklets whose name is "batt")
  refresh Position
 end tell
END

Now the important Part:

In the Script go to Code Line Nr. 10 and edit the Path to the fill.png File and also for the Output File fill_bew.png

This script takes each time it runs a predefined Bar Images, calcs the current Battery Life and resizes the Image regarding to the Result, so it does not scale the image in the Geeklet, it just screates a new one, ance done, save everything and ensure the Image Geeklet for the Bar Graph will be positioned at the right Position on top of the Background Image to fully cover the default dark Bar and to hide the red Shadow...

If you done this all right, you need to run the script once to generate a new fill_new.png in the destination Folder you have chosen in the Script above, once you see it, go to the Image Geeklet you have created in Step 2 and link it to the Now the important Part:

In the Script go to Code Line Nr. 10 and edit the Path to the fill.png File and also for the Output File fill_bew.png

This script takes each time it runs a predefined Bar Images, calcs the current Battery Life and resizes the Image regarding to the Result, so it does not scale the image in the Geeklet, it just screates a new one, ance done, save everything and ensure the Image Geeklet for the Bar Graph will be positioned at the right Position on top of the Background Image to fully cover the default dark Bar and to hide the red Shadow...

If you done this all right, you need to run the script once to generate a new fill_new.png in the destination Folder you have chosen in the Script
 newely created, no refresh time needed, all done by the Script itself

The Script will also output the Percentage left, so customize Font, Color and Size and place it above the bar e.g.

Check the Screenshot at the top to see how the final result should look like


No comments:

Post a Comment