Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- PLUGGED="enumerated 0x05ac/110c/b817 (AirPods Max USB Audio / 1)"
- UNPLUGGED="(AirPods Max USB Audio): hardware connection lost"
- IDENTIFIER="AirPods Max"
- PREVIOUS_STATE="disconnected"
- log stream --predicate 'eventMessage contains "USB"' --info | while read -r line; do
- if echo "$line" | grep -q "$IDENTIFIER"; then
- if echo "$line" | grep -iq "$PLUGGED"; then
- if [ "$PREVIOUS_STATE" != "connected" ]; then
- #echo "[$(date)] AirPods Max connected – quitting SoundSource"
- osascript -e 'tell application "SoundSource" to quit'
- osascript -e 'display notification "AirPods Max connected – SoundSource quit" with title "USB Audio Event"'
- PREVIOUS_STATE="connected"
- fi
- elif echo "$line" | grep -iq "$UNPLUGGED"; then
- if [ "$PREVIOUS_STATE" != "disconnected" ]; then
- #echo "[$(date)] AirPods Max disconnected – launching SoundSource"
- osascript -e 'tell application "SoundSource" to activate'
- osascript -e 'display notification "AirPods Max disconnected – SoundSource started" with title "USB Audio Event"'
- PREVIOUS_STATE="disconnected"
- fi
- fi
- fi
- done
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement