Skip to content

Instantly share code, notes, and snippets.

@philsnow
Created June 30, 2022 07:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save philsnow/3d41d0ae55d411f34dac504f4c02be29 to your computer and use it in GitHub Desktop.
Save philsnow/3d41d0ae55d411f34dac504f4c02be29 to your computer and use it in GitHub Desktop.
disable slack animations when on battery power

What is this?

Slack animations take a ton of CPU and thus battery. Wouldn't it be great if unplugging your laptop from its power source would automatically turn them off?

This is a bit of code for Hammerspoon that makes that happen.

AnimateSlack is just an Automator app that pulls my user token out of a keychain with security and curls a POST to some Slack API URL I forget the details of

local previousPowerSource = hs.battery.powerSource()
function batteryChangedCallback()
local powerSource = hs.battery.powerSource()
if powerSource ~= previousPowerSource then
showBatteryStatus()
hs.alert.show(powerSource)
if powerSource == "Battery Power" then
hs.alert.show("Stopping Slack animations")
hs.execute("open -a AnimateSlack --args false")
else
hs.alert.show("Starting Slack animations")
hs.execute("open -a AnimateSlack --args true")
end
previousPowerSource = powerSource;
end
end
hs.battery.watcher.new(batteryChangedCallback):start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment