Skip to content

Commit a944dee

Browse files
committed
✨ [feat][hammerspoon] auto speaker connect
1 parent 89ce228 commit a944dee

2 files changed

Lines changed: 27 additions & 0 deletions

File tree

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
-- Auto connect to speak when connected to monitor
2+
--
3+
-- Reference: https://www.hammerspoon.org/go/#usbevents
4+
5+
local monitorVendorID = 32903
6+
local speakerBluetoothAddress = "74-ca-60-56-7a-d4"
7+
8+
local BLUEUTIL = "/opt/homebrew/bin/blueutil"
9+
10+
local function usbDeviceCallback(data)
11+
if data.eventType == "added" and data.vendorID == monitorVendorID then
12+
-- print("USB event:", hs.inspect(data))
13+
print("Dell monitor connected, start connecting to speak")
14+
local ok, out = hs.execute(BLUEUTIL .. " --connect " .. speakerBluetoothAddress)
15+
if not ok then
16+
print("Failed to connect to speak:", out)
17+
else
18+
print("Successfully connected to speak")
19+
end
20+
end
21+
end
22+
23+
UsbWatcher = hs.usb.watcher.new(usbDeviceCallback)
24+
UsbWatcher:start()

pkg/macos-hammerspoon/.hammerspoon/init.lua

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ spoon.ReloadConfiguration:start()
2020
-- Auto switch input method
2121
require('auto_ime')
2222

23+
-- Auto connect to speak
24+
require('auto_speaker_connect')
25+
2326
-- Hotkeys
2427
require('hotkeys')
2528

0 commit comments

Comments
 (0)