Skip to content

Instantly share code, notes, and snippets.

@dickiedyce
Created February 13, 2022 19:26
Show Gist options
  • Save dickiedyce/cd2531a1cbf4c862f9d47aae80468a29 to your computer and use it in GitHub Desktop.
Save dickiedyce/cd2531a1cbf4c862f9d47aae80468a29 to your computer and use it in GitHub Desktop.
// Menu: Battery Monitor
// Description: Check if AC should be disconnected? Poorman's AlDente
// Author: Richard Dyce
// Twitter: @dickiedyce
// schedule: 0,15,20,45 5-22 * * *
import "@johnlindquist/kit"
const result = await exec(`pmset -g batt`)
const charge = 1 * result.stdout.match(/(\d+)\%/)[1]
const state = result.stdout.match(/(discharging|charging)/)[0]
const source = result.stdout.match(/(Battery Power|AC Power)/)[0]
if(charge > 80 && source == 'AC Power' ) {
notify(`UNPLUG! The laptop is ${state} from ${source}, at ${charge}%`)
} else if (charge < 40 && source == 'Battery Power') {
notify(`PLUG-IN! The laptop is ${state} from ${source}, at ${charge}%`)
} else {
// notify(`The laptop is ${state} from ${source}, at ${charge}%`)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment