Linux sound/volume commands

Date: 2018-07-14

Source: https://unix.stackexchange.com/questions/342554/how-to-enable-my-keyboards-volume-keys-in-xfce/342555

For binding to keyboard shortcuts:

#(Volume Up)
amixer set Master 5%+ 
#(Volume Down)
amixer set Master 5%-
# (Mute/Unmute)
amixer set Master toggle

 

# get volume: Right
amixer sget Master | grep 'Right:' | awk -F'[][]' '{ print $2 }'
85%
# get volume: Left
amixer sget Master | grep 'Left:' | awk -F'[][]' '{ print $2 }'
85%
#!/bin/bash

mute=audio-volume-muted
high=audio-volume-high
low=audio-volume-low
icon=$low

notify() {
    volume=$(amixer sget Master | grep 'Right:' | awk -F'[][]' '{ print $2 }')
    notify-send "Volume" "$volume" -u normal -t 400 -i $icon
}

notify_mute() {
    state=$(amixer sget Master | grep 'Right:' | awk -F'[][]' '{ print $4 }')
    if [ "$state" = "on" ]; then
        icon=$high
        message="Unmute"
    fi    

    if [ "$state" = "off" ]; then
        icon=$mute
        message="Mute"
    fi    
    notify-send "Volume" "$message" -u normal -t 1000 -i $icon
}

up() {
    icon=$high
    amixer set Master 5%+ 
    notify
}

down() {
    icon=$low
    amixer set Master 5%- 
    notify
}

toggle() {
    amixer set Master toggle
    notify_mute
}

if [ "$1" = "up" ]; then
    up
fi

if [ "$1" = "down" ]; then
    down
fi

if [ "$1" = "toggle" ]; then
    toggle
fi

 

 

 

 

 

11580cookie-checkLinux sound/volume commands