macOS watchdog: detect deck via ioreg sessionID
system_profiler SPUSBDataType was silently omitting the deck on some Macs (watchdog exited early, never restarted anything) and, when it did report, the trailing bus number in "Location ID: X / N" flapped without an actual replug — causing spurious restarts. ioreg sees the device reliably and sessionID changes only on real re-enumeration. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -51,20 +51,23 @@ current_addr() {
|
||||
'
|
||||
;;
|
||||
Darwin)
|
||||
# system_profiler entry per device:
|
||||
# Stream Deck XL:
|
||||
# Product ID: 0x00ba
|
||||
# Vendor ID: 0x0fd9 (Elgato ...)
|
||||
# ...
|
||||
# Location ID: 0x14140000 / 5
|
||||
# The trailing "/ N" is the bus address — it changes on replug.
|
||||
system_profiler SPUSBDataType 2>/dev/null | awk -v pids="$PIDS_RE" '
|
||||
/^[[:space:]]*Product ID:/ { pid = $3 }
|
||||
/^[[:space:]]*Vendor ID:/ { vid = $3 }
|
||||
/^[[:space:]]*Location ID:/ {
|
||||
sub(/^[[:space:]]*Location ID:[[:space:]]*/, "")
|
||||
if (vid == "0x0fd9" && pid ~ ("^0x(" pids ")$")) {
|
||||
print
|
||||
# ioreg is the reliable source on macOS — system_profiler SPUSBDataType
|
||||
# silently omits the deck on some machines, and its "Location ID: X / N"
|
||||
# trailing bus number flaps spuriously without an actual replug.
|
||||
#
|
||||
# sessionID is unique per USB enumeration session: stable while the
|
||||
# device stays plugged in, changes on every replug. Exactly what we want.
|
||||
#
|
||||
# Elgato vendor in decimal: 4057 (0x0fd9).
|
||||
# Stream Deck product IDs in decimal: 186 (0x00ba), 108 (0x006c), 109 (0x006d).
|
||||
ioreg -p IOUSB -l -w 0 2>/dev/null | awk '
|
||||
/<class IOUSBHostDevice/ { vid=""; pid=""; sid="" }
|
||||
/"idVendor"/ { vid=$NF }
|
||||
/"idProduct"/ { pid=$NF }
|
||||
/"sessionID"/ { sid=$NF }
|
||||
/}/ {
|
||||
if (vid == "4057" && (pid == "186" || pid == "108" || pid == "109") && sid != "") {
|
||||
print sid
|
||||
exit
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user