Skip to content

Instantly share code, notes, and snippets.

@andersx
Created July 9, 2020 05:17
Show Gist options
  • Save andersx/ce95dc0fa5143bffd1caef2c1d59345d to your computer and use it in GitHub Desktop.
Save andersx/ce95dc0fa5143bffd1caef2c1d59345d to your computer and use it in GitHub Desktop.
Toggle speakers/headphones for Creative Soundblasterx AE-5 on with amixer
#!/usr/bin/env bash
# Grep which device is Creative
AMIXEROUTPUT=$(aplay -l | grep -m1 Creative)
DEVICE=${AMIXEROUTPUT:5:1}
# Grep for connected headphones
OUTPUT=$(amixer -c $DEVICE sget "Output Select" | grep "Item0: 'Headphone'")
echo $AMIXEROUTPUT
echo "Device" $DEVICE
echo $OUTPUT
# If string was empty no headphones were connected
if [[ -z $OUTPUT ]]; then
amixer -c $DEVICE sset 'Output Select' 'Headphone'
# If there was a string, connect Line Out
else
amixer -c $DEVICE sset 'Output Select' 'Line Out'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment