Skip to content

Commit

Permalink
Add shush-like functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
adamyonk committed Mar 8, 2017
1 parent 6e26299 commit 6d20641
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
1 change: 1 addition & 0 deletions hammerspoon/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ require('control-escape')
require('delete-words')
require('hyper')
require('markdown')
require('microphone')
require('panes')
require('super')
require('windows')
Expand Down
60 changes: 60 additions & 0 deletions hammerspoon/microphone.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
local message = require('status-message')

local messageMuting = message.new('muted 🎤')
local messageHot = message.new('hot 🎤')
local last_mods = {}
local recently_clicked = false
local second_click = false

display_status = function ()
-- Check if the active mic is muted
if hs.audiodevice.current(true).device:muted() then
messageMuting:notify()
else
messageHot:notify()
end
end
display_status()

toggle = function (device)
if device:muted() then
device:setMuted(false)
else
device:setMuted(true)
end
end

control_key_handler = function()
recently_clicked = false
end

control_key_timer = hs.timer.delayed.new(0.3, control_key_handler)

option_handler = function(event)
local device = hs.audiodevice.current(true).device
local new_mods = event:getFlags()

-- alt keyDown
if new_mods['alt'] == true then
toggle(device)
if recently_clicked == true then
display_status()
second_click = true
end
recently_clicked = true
control_key_timer:start()

-- alt keyUp
elseif last_mods['alt'] == true and new_mods['alt'] == nil then
if second_click then
second_click = false
else
toggle(device)
end
end

last_mods = new_mods
end

option_key = hs.eventtap.new({hs.eventtap.event.types.flagsChanged}, option_handler)
option_key:start()
5 changes: 5 additions & 0 deletions hammerspoon/status-message.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,11 @@ statusmessage.new = function(messageText)
self.text:delete()
self.text = nil
end
end,
notify = function(self, seconds)
local seconds = seconds or 1
self:show()
hs.timer.delayed.new(seconds, function () return self:hide() end):start()
end
}
end
Expand Down

0 comments on commit 6d20641

Please sign in to comment.