You are not logged in.

#1 2013-03-10 02:04:09

v43
Member
Registered: 2011-02-03
Posts: 140

a simple script to switch between Xonar Essence STX outputs

Hi, I've written a simple bash script to switch between a Xonar Essence STX output.
You can set different volume settings for headphones and line out.
You can have a popup appear on your desktop with notify-osd.

here it is:

#!/bin/bash


# choose the master volume for headphones output
headvol=35
# and line out
linevol=100

# choose an icon for the heaphones output to be shown in the popup
headicon=audio-headphones
# and one for the line-out
lineicon=audio-input-line


# find the device number
STX="$(cat /proc/asound/cards | grep STX)"
STX=${STX:1:2}

# find the current output
COUT="$(amixer -c $STX sget 'Analog Output' | grep Item0 | sed -e 's/  Item0: //g')"

# list all outputs
declare -a OUTA=("'Speakers'" "'Headphones'" "'FP Headphones'")



# let's bind the current output name to an index number
idx=0
ICON=$headicon
VOL=$headvol

while [[ $idx -lt "${#OUTA[@]}" ]]; do
    if [[ "${OUTA[$idx]}" = "$COUT" ]]; then
	break
    fi
    idx=$((idx+1));
done


let idx="idx +1"
if [[ $idx -eq 3 ]]; then 
  let idx=0
  
  ICON=$lineicon
  VOL=$linevol
fi



# show the popup
notify-send \
  --app-name=Xonar-switcher \
  --expire-time=5000 \
  --icon=$ICON \
  "<br><br>Output:  ${OUTA[$idx]}<br>$VOL%"


# change the output
eval "amixer -c $STX sset 'Analog Output' ${OUTA[$idx]} > /dev/null"

# set the master volume
eval "amixer -c $STX set Master $VOL% > /dev/null"

Last edited by v43 (2013-03-10 02:19:06)

Offline

Board footer

Powered by FluxBB