我写了一个spoon脚本来控制音量,但是hotkeys.bind
方法不起作用,是什么问题?
这是init.lua
勺子的
-- === Volume ===
local obj={}
obj.__index = obj
-- Metadata
obj.name = "Volume"
obj.version = "1.0"
obj.license = "MIT - https://opensource.org/licenses/MIT"
obj.logger = hs.logger.new('Volume')
function obj:init()
end
function obj:changeVolume(diff)
return function()
local current = hs.audiodevice.defaultOutputDevice():volume()
local new = math.min(100, math.max(0, math.floor(current + diff)))
if new > 0 then
hs.audiodevice.defaultOutputDevice():setMuted(false)
end
hs.alert.closeAll(0.0)
hs.alert.show("Volume " .. new .. "%", {}, 0.5)
hs.audiodevice.defaultOutputDevice():setVolume(new)
end
end
return obj
我把这个勺子装进去并用~/.hammerspoon/init.lua
了
hs.loadSpoon("Volume")
hs.hotkey.bind({'cmd', 'alt'}, '[', function() spoon.Volume:changeVolume(-3) end)
hs.hotkey.bind({'cmd', 'alt'}, ']', function() spoon.Volume:changeVolume(3) end)