Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (*
- batteryHealthMeter
- (C) Applehelpwriter.com / Phil Stokes 2014
- See: http://wp.me/p1ItrK-ZT
- for details
- *)
- on returnNumbersInString(inputString)
- set s to quoted form of inputString
- do shell script "sed s/[a-zA-Z\\']//g <<< " & s
- set dx to the result
- set numlist to {}
- repeat with i from 1 to count of words in dx
- set this_item to word i of dx
- try
- set this_item to this_item as number
- set the end of numlist to this_item
- end try
- end repeat
- return numlist
- end returnNumbersInString
- on powerstats()
- set iconAC to "🔌 "
- set iconBatt to "🔋 "
- set iconCharge to "⚡️ "
- set iconTime to "🕒 "
- set iconHealth to "🍀 "
- set iconCycles to "🌀 "
- set iconWarning to "⚠️ "
- do shell script "pmset -g everything | grep Cycles"
- set x to the result
- set charging to word 2 of x
- if charging contains "Not" then
- set charger to " (not charging!) " & iconWarning
- else
- set charger to " (charging)"
- end if
- if word 1 of x is "AC" then
- set _t to "Time to Full: "
- set pwr to "AC"
- set pwrSource to iconAC
- else
- set _t to "Time Remaining: "
- set pwr to "Batt"
- set pwrSource to iconBatt
- set charger to ""
- end if
- set nums to returnNumbersInString(x)
- set percentage to item 1 of nums & "%"
- if item 5 of nums = 0 then
- set hrmins to " mins"
- else if item 5 of nums = 1 then
- set hrmins to " hr"
- else
- set hrmins to " hrs"
- end if
- if item 5 of nums is greater than 4 then
- if pwr is "AC" then
- set t to "Calculating...try refresh in 2 mins"
- end if
- else
- if item 6 of nums is less than 10 then
- set theMins to item 6 of nums as string
- set theMins to "0" & theMins as string
- else
- set theMins to item 6 of nums as integer
- end if
- set t to item 5 of nums & ":" & theMins & hrmins
- end if
- set FCC to item 3 of nums as integer
- set designCap to item 4 of nums as integer
- set battHealth to (FCC / (designCap / 100))
- set battHealth to round (battHealth)
- set battHealth to battHealth & "%"
- set cycles to item -3 of nums
- display dialog pwrSource & "Power Source: " & pwr & charger & return & iconCharge & "Current Charge: " & percentage & return & iconTime & _t & t & return & return & iconHealth & "Battery Health: " & battHealth & return & iconCycles & "Cycles: " & cycles with title "Battery Power Stats" buttons {"Refresh", "OK"} default button "OK" with icon 1
- if button returned of the result is "Refresh" then
- powerstats()
- end if
- end powerstats
- powerstats()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement