10

Disk Used graphic

Posted in System by Ivyleaf 134 days ago

This geeklet displays the current disk usage % as a horizontal bar. Included here is just the geeklet for the value bar itself which includes all the actual code. To replicate the screenshot, all that is required are two other Shell Geeklets, one with the command echo "Disk Used", and one just empty but with a background colour and layered behind to give the full bar size (if required).

The active Geeklet itself it quite simple, retrieving a single value from the shell (in this case the Disk Usage Percent, but this could easily be substituted for any other single value such as CPU usage) and then resizing the Geeklet itself accordingly with inline AppleScript.

#Variable to specify the desired full width of the bar (if the vale was 100%)
FULLW=200

#Get the disk used %
DISKUSED=`df | awk '/dev\/disk0s2/ && NF>1 {print $5}' | sed 's/\%//'`

#Calculate the scale width of the bar based on the disk used %
BARW=$(echo "$DISKUSED * $FULLW / 100" | bc)

#Update the width of the geeklet
osascript -e "tell application \"GeekTool Helper\" to set width of first item of (geeklets whose name is \"DiskUsed Bar\") to $BARW"

#Display the disk used % as text in the bar (delete line if not required)
echo $DISKUSED

Geeklet files to download

Comments

Log in to comment or register here.