Last active
August 25, 2026 02:53
-
-
Save ericswpark/5d83ca90057160a2e89f932a3ae7cbec to your computer and use it in GitHub Desktop.
Switches profiles automatically on a Framework 13 with AMD Ryzen AI chipset audio
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ~/.config/systemd/user/ucm-auto-switch.service | |
| [Unit] | |
| Description=Switch profile when input device changes | |
| After=pipewire.service pipewire-pulse.service | |
| Wants=pipewire-pulse.service | |
| [Service] | |
| Type=simple | |
| ExecStart=%h/.local/bin/ucm-auto-switch.sh # change this to where you saved the script obviously | |
| Restart=on-failure | |
| RestartSec=3s | |
| [Install] | |
| WantedBy=default.target |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # pactl list cards short | |
| CARD_NAME="alsa_card.pci-0000_c1_00.6" | |
| LAST_SWITCH=0 | |
| switch_profile() { | |
| NOW=$(date +%s) | |
| ELAPSED=$((NOW - LAST_SWITCH)) | |
| if [ "$ELAPSED" -lt 3 ]; then | |
| return | |
| fi | |
| HEADPHONES_AVAILABLE=$(pactl --format=json list cards | jq -r --arg card "$CARD_NAME" '.[] | select(.name == $card) | .ports["[Out] Headphones"].availability') | |
| if [ "$HEADPHONES_AVAILABLE" = "available" ]; then | |
| echo "Headphones available, switching profile..." | |
| pactl set-card-profile "$CARD_NAME" "HiFi (Headphones, Headset, Mic1)" | |
| else | |
| echo "Speakers available, switching profile..." | |
| pactl set-card-profile "$CARD_NAME" "HiFi (Mic1, Mic2, Speaker)" | |
| fi | |
| LAST_SWITCH=$(date +%s) | |
| } | |
| switch_profile | |
| pactl subscribe | grep --line-buffered "Event 'change' on card" | while read -r line; do | |
| sleep 0.5 | |
| switch_profile | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment