Skip to content

Commit

Permalink
Fork MicMute to support my stupid headset with no input mute
Browse files Browse the repository at this point in the history
  • Loading branch information
adamgibbins committed Mar 12, 2019
1 parent 7d4a2db commit d5f2788
Show file tree
Hide file tree
Showing 3 changed files with 235 additions and 2 deletions.
125 changes: 125 additions & 0 deletions Spoons/MicMuteFork.spoon/docs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
[
{
"Constant" : [

],
"submodules" : [

],
"Function" : [

],
"Variable" : [

],
"stripped_doc" : [

],
"type" : "Module",
"Deprecated" : [

],
"desc" : "Microphone Mute Toggle and status indicator",
"Constructor" : [

],
"doc" : "Microphone Mute Toggle and status indicator\n\nDownload: [https:\/\/github.com\/dctucker\/Spoons\/raw\/master\/Spoons\/MicMute.spoon.zip](https:\/\/github.com\/dctucker\/Spoons\/raw\/master\/Spoons\/MicMute.spoon.zip)",
"Method" : [
{
"doc" : "Toggle mic mute on\/off",
"stripped_doc" : [
"Toggle mic mute on\/off"
],
"parameters" : [

],
"def" : "MicMute:toggleMicMute()",
"notes" : [

],
"signature" : "MicMute:toggleMicMute()",
"type" : "Method",
"returns" : [

],
"name" : "toggleMicMute",
"desc" : "Toggle mic mute on\/off"
},
{
"doc" : "Binds hotkeys for MicMute\n\nParameters:\n * mapping - A table containing hotkey modifier\/key details for the following items:\n * toggle - This will cause the microphone mute status to be toggled. Hold for momentary, press quickly for toggle.\n * latch_timeout - Time in seconds to hold the hotkey before momentary mode takes over, in which the mute will be toggled again when hotkey is released. Latch if released before this time. 0.75 for 750 milliseconds is a good value.",
"stripped_doc" : [
"Binds hotkeys for MicMute",
""
],
"parameters" : [
" * mapping - A table containing hotkey modifier\/key details for the following items:",
" * toggle - This will cause the microphone mute status to be toggled. Hold for momentary, press quickly for toggle.",
" * latch_timeout - Time in seconds to hold the hotkey before momentary mode takes over, in which the mute will be toggled again when hotkey is released. Latch if released before this time. 0.75 for 750 milliseconds is a good value."
],
"def" : "MicMute:bindHotkeys(mapping, latch_timeout)",
"notes" : [

],
"signature" : "MicMute:bindHotkeys(mapping, latch_timeout)",
"type" : "Method",
"returns" : [

],
"name" : "bindHotkeys",
"desc" : "Binds hotkeys for MicMute"
}
],
"Command" : [

],
"Field" : [

],
"items" : [
{
"doc" : "Binds hotkeys for MicMute\n\nParameters:\n * mapping - A table containing hotkey modifier\/key details for the following items:\n * toggle - This will cause the microphone mute status to be toggled. Hold for momentary, press quickly for toggle.\n * latch_timeout - Time in seconds to hold the hotkey before momentary mode takes over, in which the mute will be toggled again when hotkey is released. Latch if released before this time. 0.75 for 750 milliseconds is a good value.",
"stripped_doc" : [
"Binds hotkeys for MicMute",
""
],
"parameters" : [
" * mapping - A table containing hotkey modifier\/key details for the following items:",
" * toggle - This will cause the microphone mute status to be toggled. Hold for momentary, press quickly for toggle.",
" * latch_timeout - Time in seconds to hold the hotkey before momentary mode takes over, in which the mute will be toggled again when hotkey is released. Latch if released before this time. 0.75 for 750 milliseconds is a good value."
],
"def" : "MicMute:bindHotkeys(mapping, latch_timeout)",
"notes" : [

],
"signature" : "MicMute:bindHotkeys(mapping, latch_timeout)",
"type" : "Method",
"returns" : [

],
"name" : "bindHotkeys",
"desc" : "Binds hotkeys for MicMute"
},
{
"doc" : "Toggle mic mute on\/off",
"stripped_doc" : [
"Toggle mic mute on\/off"
],
"parameters" : [

],
"def" : "MicMute:toggleMicMute()",
"notes" : [

],
"signature" : "MicMute:toggleMicMute()",
"type" : "Method",
"returns" : [

],
"name" : "toggleMicMute",
"desc" : "Toggle mic mute on\/off"
}
],
"name" : "MicMute"
}
]
107 changes: 107 additions & 0 deletions Spoons/MicMuteFork.spoon/init.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
--- === MicMute ===
---
--- Microphone Mute Toggle and status indicator
---
--- Download: [https://github.com/dctucker/Spoons/raw/master/Spoons/MicMute.spoon.zip](https://github.com/dctucker/Spoons/raw/master/Spoons/MicMute.spoon.zip)

local obj={}
obj.__index = obj

-- Metadata
obj.name = "MicMuteFork"
obj.version = "1.0"
obj.author = "dctucker <[email protected]>"
obj.homepage = "https://dctucker.com"
obj.license = "MIT - https://opensource.org/licenses/MIT"

function obj:updateMicMute()
if hs.audiodevice.defaultInputDevice():inputVolume() <= 1 then
obj.mute_menu:setTitle("📵 Off")
hs.alert('Muted', 1)
else
obj.mute_menu:setTitle("🎙 On")
hs.alert('Unmuted', 1)
end
end

--- MicMute:toggleMicMute()
--- Method
--- Toggle mic mute on/off
---
function obj:toggleMicMute()
local mic = hs.audiodevice.defaultInputDevice()
local zoom = hs.application'Zoom'
if mic:inputVolume() == 0 then
mic:setInputVolume(50)
if zoom then
local ok = zoom:selectMenuItem'Unmute Audio'
if not ok then
hs.timer.doAfter(0.5, function()
zoom:selectMenuItem'Unmute Audio'
end)
end
end
else
mic:setInputVolume(0)
if zoom then
local ok = zoom:selectMenuItem'Mute Audio'
if not ok then
hs.timer.doAfter(0.5, function()
zoom:selectMenuItem'Mute Audio'
end)
end
end
end
obj:updateMicMute()
end

--- MicMute:bindHotkeys(mapping, latch_timeout)
--- Method
--- Binds hotkeys for MicMute
---
--- Parameters:
--- * mapping - A table containing hotkey modifier/key details for the following items:
--- * toggle - This will cause the microphone mute status to be toggled. Hold for momentary, press quickly for toggle.
--- * latch_timeout - Time in seconds to hold the hotkey before momentary mode takes over, in which the mute will be toggled again when hotkey is released. Latch if released before this time. 0.75 for 750 milliseconds is a good value.
function obj:bindHotkeys(mapping, latch_timeout)
if (self.hotkey) then
self.hotkey:delete()
end
local mods = mapping["toggle"][1]
local key = mapping["toggle"][2]

if latch_timeout then
self.hotkey = hs.hotkey.bind(mods, key, function()
self:toggleMicMute()
self.time_since_mute = hs.timer.secondsSinceEpoch()
end, function()
if hs.timer.secondsSinceEpoch() > self.time_since_mute + latch_timeout then
self:toggleMicMute()
end
end)
else
self.hotkey = hs.hotkey.bind(mods, key, function()
self:toggleMicMute()
end)
end

return self
end

function obj:init()
obj.time_since_mute = 0
obj.mute_menu = hs.menubar.new()
obj.mute_menu:setClickCallback(function()
obj:toggleMicMute()
end)
obj:updateMicMute()

hs.audiodevice.watcher.setCallback(function(arg)
if string.find(arg, "dIn ") then
obj:updateMicMute()
end
end)
hs.audiodevice.watcher.start()
end

return obj
5 changes: 3 additions & 2 deletions audio.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
spoon.SpoonInstall:andUse('MicMute')
spoon.MicMute:bindHotkeys({ toggle = {modHyper, '`'}}, 0.75)
-- Fork of MicMute spoon that turns mute into vol 0 as muting input also results in muting output with my device
hs.loadSpoon('MicMuteFork')
spoon.MicMuteFork:bindHotkeys({ toggle = {modHyper, '`'}}, 0.75)

function setMusicDevice()
local musicDevice
Expand Down

0 comments on commit d5f2788

Please sign in to comment.