Last active
May 29, 2022 11:01
-
-
Save Hiradur/d9e62acec862878cd9074cae8f787b12 to your computer and use it in GitHub Desktop.
Shell script to toggle video and audio output between two setups (different displays and audio systems) using X.org and Pulseaudio
This file contains 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
#!/bin/sh | |
# toggle_av_setups.sh | |
# Original author: Hiradur | |
# License: CC0 | |
# This script toggles video and audio output between two setups: | |
# 1. monitor with stereo speakers on desk | |
# 2. TV with 5.1 surround sound | |
# only one of these screens is enabled at a given time | |
# It can be mapped to a key combination to be able to switch between the screens without having to turn on the currently active screen only to switch to the other. | |
# To accomodate for your own setup you would need to change: | |
# - video output names (determine with `xrandr`) | |
# - display resolutions, refresh rates | |
# - audio sink names (determine with `pacmd list-sinks`) | |
# switch to desktop screen if TV is the primary screen | |
if xrandr | grep primary | grep "HDMI-0"; then | |
# switch to desktop screen | |
xrandr --output DP-1 --primary --auto \ | |
--output HDMI-0 --off | |
# wait until the HDMI audio output for the desktop speakers is available | |
sleep 7s | |
# first switch back from 5.1 surround to stereo profile | |
pacmd set-card-profile 0 output:hdmi-stereo-extra2 | |
# switch audio output to desktop audio | |
pacmd set-default-sink "alsa_output.pci-0000_02_00.1.hdmi-stereo-extra2" | |
else | |
# switch to TV screen and force refresh rate (necessary for my TV) | |
xrandr --output HDMI-0 --primary --rate "59.94" --mode 1920x1080 \ | |
--output DP-1 --off | |
# wait until the HDMI audio output for the TV is available | |
sleep 7s | |
# configure audio | |
# first try stereo audio output for TV in case surround output is not listed | |
pacmd set-default-sink "alsa_output.pci-0000_02_00.1.hdmi-stereo-extra1" | |
# now try surround output | |
pacmd set-default-sink "alsa_output.pci-0000_02_00.1.hdmi-surround-extra1" | |
# switch to 5.1 surround profile | |
# see https://www.whatsdoom.com/posts/2015/12/01/configure-pulseaudio-output-via-command-line/ | |
pacmd set-card-profile 0 output:hdmi-surround-extra1 | |
# launch software | |
antimicro --tray --profile ~/controller_mappings/Desktop.gamecontroller.amgp & | |
lutris | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment