Caffeinate via Hammerspoon

caffeine = hs.menubar.new()

function setCaffeineDisplay(state)
	if state then
		caffeine:setTitle("☕️")
		caffeine:setTooltip("Device is being kept awake")
	else
		caffeine:setTitle("😴")
		caffeine:setTooltip("Device is allowed to sleep")
	end
end

function caffeineClicked(modifiers)
	if modifiers.ctrl then -- quit on ctrl-click
		caffeine:delete()
	else
		setCaffeineDisplay(hs.caffeinate.toggle('displayIdle'))
	end
end

if caffeine then
	caffeine:setClickCallback(caffeineClicked)
	setCaffeineDisplay(hs.caffeinate.get("displayIdle"))
end

A quick modification of the Hammerspoon example for making a caffeinate clone in Lua. It was actually easier to understand than I imagined, and it seems like there is so much more that it can do. I just need to get up to speed on Lua.

Respond via email.