Skip to content

Instantly share code, notes, and snippets.

@lukasroegner
Created December 4, 2019 11:59
Show Gist options
  • Save lukasroegner/94bc75fd71085e8a34f0f430ee378ea3 to your computer and use it in GitHub Desktop.
Save lukasroegner/94bc75fd71085e8a34f0f430ee378ea3 to your computer and use it in GitHub Desktop.
Automatic display brightness based on whether AC is connected
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