Created
July 27, 2025 15:29
-
-
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.
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 | |
| # 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