Skip to content

Instantly share code, notes, and snippets.

@mag37
Created July 27, 2025 15:29
Show Gist options
  • Select an option

  • Save mag37/1e23212da7e1a62cd5dab6066ab405e2 to your computer and use it in GitHub Desktop.

Select an option

Save mag37/1e23212da7e1a62cd5dab6066ab405e2 to your computer and use it in GitHub Desktop.
A script to swap between 2 sets of audio+video outputs in KDE. Like TV+Desktop.
#!/usr/bin/env bash
# Enable/Activate both monitors and get info from `kscreen-doctor -o | grep -A3 Output`
# Get audio sinks from `pactl list sinks short`
monitorMain="DP-2"
audioMain="alsa_output.pci-0000_0a_00.3.analog-stereo"
monitorTV="HDMI-0"
audioTV="alsa_output.pci-0000_08_00.1.hdmi-stereo"
fullSwap="false" # when set to false we'll only swap primary - not disable the secondary
currentPrimary=$(kscreen-doctor -o | grep -B 4 "priority 1" | awk '/Output/{ print $3 }')
if [[ "$currentPrimary" == "$monitorMain" ]]; then
if [[ "$fullSwap" == "true" ]]; then
kscreen-doctor output.${monitorTV}.enable output.${monitorTV}.primary output.${monitorMain}.disable
else
kscreen-doctor output.${monitorTV}.primary
fi
sleep 1
pactl set-default-sink "${audioTV}"
else
if [[ "$fullSwap" == "true" ]]; then
kscreen-doctor output.${monitorMain}.enable output.${monitorMain}.primary output.${monitorTV}.disable
else
kscreen-doctor output.${monitorMain}.primary
fi
sleep 1
pactl set-default-sink "${audioMain}"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment