mag37 revised this gist 2 hours ago. Go to revision
1 file changed, 5 insertions
KDE_monitor_audio-swap.md
| @@ -1,3 +1,7 @@ | |||
| 1 | + | A small script to swap between main monitor+audio source to secondary monitor+audio. Either just swap which is set as primary, or also disable the secondary. | |
| 2 | + | Add "Command or Script" shortcut to trigger it from the keyboard. | |
| 3 | + | ||
| 4 | + | ```sh | |
| 1 | 5 | #!/usr/bin/env bash | |
| 2 | 6 | ||
| 3 | 7 | ||
| @@ -30,3 +34,4 @@ else | |||
| 30 | 34 | sleep 1 | |
| 31 | 35 | pactl set-default-sink "${audioMain}" | |
| 32 | 36 | fi | |
| 37 | + | ``` | |
mag37 revised this gist 2 hours ago. Go to revision
1 file changed, 32 insertions
KDE_monitor_audio-swap.md(file created)
| @@ -0,0 +1,32 @@ | |||
| 1 | + | #!/usr/bin/env bash | |
| 2 | + | ||
| 3 | + | ||
| 4 | + | # Enable/Activate both monitors and get info from `kscreen-doctor -o | grep -A3 Output` | |
| 5 | + | # Get audio sinks from `pactl list sinks short` | |
| 6 | + | ||
| 7 | + | monitorMain="DP-2" | |
| 8 | + | audioMain="alsa_output.pci-0000_0a_00.3.analog-stereo" | |
| 9 | + | monitorTV="HDMI-0" | |
| 10 | + | audioTV="alsa_output.pci-0000_08_00.1.hdmi-stereo" | |
| 11 | + | fullSwap="false" # when set to false we'll only swap primary - not disable the secondary | |
| 12 | + | ||
| 13 | + | currentPrimary=$(kscreen-doctor -o | grep -B 4 "priority 1" | awk '/Output/{ print $3 }') | |
| 14 | + | ||
| 15 | + | if [[ "$currentPrimary" == "$monitorMain" ]]; then | |
| 16 | + | if [[ "$fullSwap" == "true" ]]; then | |
| 17 | + | kscreen-doctor output.${monitorTV}.enable output.${monitorTV}.primary output.${monitorMain}.disable | |
| 18 | + | else | |
| 19 | + | kscreen-doctor output.${monitorTV}.primary | |
| 20 | + | fi | |
| 21 | + | sleep 1 | |
| 22 | + | pactl set-default-sink "${audioTV}" | |
| 23 | + | ||
| 24 | + | else | |
| 25 | + | if [[ "$fullSwap" == "true" ]]; then | |
| 26 | + | kscreen-doctor output.${monitorMain}.enable output.${monitorMain}.primary output.${monitorTV}.disable | |
| 27 | + | else | |
| 28 | + | kscreen-doctor output.${monitorMain}.primary | |
| 29 | + | fi | |
| 30 | + | sleep 1 | |
| 31 | + | pactl set-default-sink "${audioMain}" | |
| 32 | + | fi | |