Skip to content

Instantly share code, notes, and snippets.

@Trung-DV
Created March 30, 2024 05:37
Show Gist options
  • Save Trung-DV/df02ffc3bb1b910b6d32eeb54e269311 to your computer and use it in GitHub Desktop.
Save Trung-DV/df02ffc3bb1b910b6d32eeb54e269311 to your computer and use it in GitHub Desktop.
Hammerspoon script to change Microphone from AirPods to MacBook Microphone
local MICROPHONE_DEVICE_NAME = "MacBook Pro Microphone"
function detectAirPods(event)
if event ~= "dOut" and event ~= "dIn " then
return
end
local device_name = hs.audiodevice.current().name
if device_name:find("AirPods") == nil then
return
end
local microphone = hs.audiodevice.findInputByName(MICROPHONE_DEVICE_NAME)
if (microphone ~= nil) then
microphone:setDefaultInputDevice()
-- hs.notify.show("AirPods", "","Use "..MICROPHONE_DEVICE_NAME)
end
hs.notify.show("Mic","Current device",hs.audiodevice.defaultInputDevice():name())
end
hs.audiodevice.watcher.setCallback(detectAirPods)
hs.audiodevice.watcher.start()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment