Skip to content

Instantly share code, notes, and snippets.

@ericswpark
Last active August 25, 2026 02:53
Show Gist options
  • Select an option

  • Save ericswpark/5d83ca90057160a2e89f932a3ae7cbec to your computer and use it in GitHub Desktop.

Select an option

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
# ~/.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
#!/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