-
Notifications
You must be signed in to change notification settings - Fork 0
/
muteMic.lua
106 lines (85 loc) · 2.25 KB
/
muteMic.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
-- disable animation
hs.window.animationDuration = 0
local cac = {"cmd", "alt", "ctrl"}
----
-- source: https://github.com/cmsj/hammerspoon-config/blob/master/init.lua#L137
-- Toggle Skype between muted/unmuted, whether it is focused or not
function toggleSkypeMute()
local skype = hs.appfinder.appFromName("Skype")
if not skype then
return
end
local lastapp = nil
if not skype:isFrontmost() then
lastapp = hs.application.frontmostApplication()
skype:activate()
end
if not skype:selectMenuItem({"Conversations", "Mute Microphone"}) then
skype:selectMenuItem({"Conversations", "Unmute Microphone"})
end
if lastapp then
lastapp:activate()
end
end
----
local muteCircle = nil
function removeCircle(circle)
if circle then
circle:delete()
end
end
function createMuteCircle()
muteCircle = hs.drawing.circle(hs.geometry.rect(20, 40, 80, 80))
muteCircle:setFillColor({["red"]=0, ["green"]=0, ["blue"]=0, ["alpha"]=0.5})
muteCircle:setFill(true)
muteCircle:setStroke(true)
end
function drawMuteCircle()
removeCircle(muteCircle)
createMuteCircle()
muteCircle:show()
end
----
-- source: https://github.com/squaresurf/hammerspoon-castle/blob/master/home/.hammerspoon/init.lua#L70-L95
function micIsMuted()
status, volume = hs.applescript.applescript('get volume settings')
if status then
invl = volume:match("invl':(%d+)")
if invl == '0' then
return true
else
return false
end
end
end
function displayIfMicIsMuted(isMuted)
if isMuted == nil then
hs.alert.show("Not sure if the Mic is muted.")
elseif isMuted then
drawMuteCircle()
else
removeCircle(muteCircle)
end
end
-- Toggle mic mute
function muteMic()
hs.applescript.applescript('set volume input volume 0')
end
function unmuteMic()
hs.applescript.applescript('set volume input volume 75')
end
function toggleMicMute()
-- muted = micIsMuted()
-- if muted then
-- unmuteMic()
-- else
-- muteMic()
-- end
-- displayIfMicIsMuted()
device = hs.audiodevice.defaultInputDevice()
device:setMuted(not device:muted())
displayIfMicIsMuted(device:muted())
end
-- enable the mic by default
unmuteMic()
hs.hotkey.bind(cac, 'M', toggleMicMute)