Skip to content

Instantly share code, notes, and snippets.

@jdbrice
Created September 5, 2018 02:16
Show Gist options
  • Save jdbrice/eaf19c94f7562d41fff932c43b3c7510 to your computer and use it in GitHub Desktop.
Save jdbrice/eaf19c94f7562d41fff932c43b3c7510 to your computer and use it in GitHub Desktop.
battery widget applescript for better touch tools
set theList to paragraphs of text of (do shell script "pmset -g batt")
set percent to word 6 of theList's item 2
set charge to word 7 of theList's item 2
if (charge = "charging") then
set iconC to "⚡️"
else
set iconC to ""
end if
set remainingRaw to my split(theList's item 2, " ")
set remainingTime to remainingRaw's item 5
if (remainingTime = "(no") then
set strTime to " (?)"
else if (remainingTime = "0:00") then
set strTime to ""
else
set strTime to " (" & remainingTime & ")"
end if
return iconC & percent & "%" & strTime
to split(someText, delimiter)
set AppleScript's text item delimiters to delimiter
set someText to someText's text items
set AppleScript's text item delimiters to {""}
return someText
end split
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment