Skip to content

Instantly share code, notes, and snippets.

@philsnow
Last active June 30, 2022 07:24
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/4086e07b28d8d3cd17f5bf81ff85357f to your computer and use it in GitHub Desktop.
Save philsnow/4086e07b28d8d3cd17f5bf81ff85357f to your computer and use it in GitHub Desktop.
disable slack animations 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 api.slack.com, but if I were to do this again I'd just have Hammerspoon do it.

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