Created
December 4, 2019 11:59
-
-
Save lukasroegner/94bc75fd71085e8a34f0f430ee378ea3 to your computer and use it in GitHub Desktop.
Automatic display brightness based on whether AC is connected
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const systeminformation = require('systeminformation'); | |
const osxBrightness = require('osx-brightness'); | |
let lastIsAcConnectedState = null; | |
systeminformation.battery(data => { | |
lastIsAcConnectedState = data.acconnected; | |
setInterval(() => { | |
systeminformation.battery(data => { | |
if (data.acconnected) { | |
if (lastIsAcConnectedState === false) { | |
lastIsAcConnectedState = true; | |
osxBrightness.set(1); | |
} | |
} else { | |
if (lastIsAcConnectedState === true) { | |
lastIsAcConnectedState = false; | |
osxBrightness.set(0.75); | |
} | |
} | |
}); | |
}, 30 * 1000); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment