-
Notifications
You must be signed in to change notification settings - Fork 0
/
AudioSwitcher.lua
61 lines (47 loc) · 1.42 KB
/
AudioSwitcher.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
---
--- Generated by Luanalysis
--- Created by muescha.
--- DateTime: 16.12.22 20:41
--- source: https://github.com/dbalatero/dotfiles/blob/master/hammerspoon/audio-switcher.lua
---
fileInfo()
local function getDeviceChoices()
local devices = hs.audiodevice.allOutputDevices()
local choices = {}
currentUid = hs.audiodevice.current(false).uid
-- 🔘⚪
-- ☐☑
for i, device in ipairs(devices) do
icon = '🔊'
if device:outputMuted() then
icon = '🔇'
end
local subText = icon
if device:outputVolume() then
subText = subText .. ' Volume ' .. math.floor(device:outputVolume()) .. '%'
end
choices[i] = {
text = ( currentUid == device:uid() and "➜ " or " ") .. device:name(),
subText = " " .. subText,
uuid = device:uid(),
}
end
return choices
end
local function handleAudioChoice(choice)
if not choice then
return
end
local device = hs.audiodevice.findDeviceByUID(choice['uuid'])
device:setDefaultOutputDevice()
device:setOutputMuted(false)
hs.alert('Switched to ' .. choice['text'])
end
----------
local audioChooser = hs.chooser.new(handleAudioChoice)
audioChooser:width(40)
hs.hotkey.bind(hyper, '7',keyInfo("Audio Switcher"), function()
local choices = getDeviceChoices()
audioChooser:choices(choices)
audioChooser:show()
end)