Skip to content

Instantly share code, notes, and snippets.

@mfaerevaag
Last active April 8, 2018 12:40

Revisions

  1. mfaerevaag revised this gist Apr 8, 2018. 1 changed file with 8 additions and 8 deletions.
    16 changes: 8 additions & 8 deletions vol.sh
    Original file line number Diff line number Diff line change
    @@ -7,13 +7,13 @@ signal() {

    # change after your setup
    CARD='0'
    MIXERS="Master Front Surround Center LFE"
    CHANNELS="Master Front Surround Center LFE"

    # get "muted" or "unmuted"
    get_state() {
    res="unmuted"

    for m in $MIXERS; do
    for m in $CHANNELS; do
    if amixer -c $CARD get $m | grep '\[off\]' > /dev/null; then
    res="muted"
    break;
    @@ -23,10 +23,10 @@ get_state() {
    echo $res
    }

    # run for all playable mixers
    for_all_mixers() {
    for m in $MIXERS; do
    amixer -c $CARD set $m $1 > /dev/null
    # run for all playable channels
    for_all_channels() {
    for channel in $CHANNELS; do
    amixer -c $CARD set $channel $1 > /dev/null
    done
    }

    @@ -47,14 +47,14 @@ then

    elif [[ $1 == "unmute" ]]
    then
    for_all_mixers "unmute"
    for_all_channels "unmute"
    signal

    elif [[ $1 == "toggle" ]]
    then
    state=`get_state`
    if [ "$state" == "muted" ]; then
    for_all_mixers "unmute"
    for_all_channels "unmute"
    else
    amixer -c $CARD set Master mute > /dev/null
    fi
  2. mfaerevaag created this gist Apr 8, 2018.
    70 changes: 70 additions & 0 deletions vol.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,70 @@
    #!/bin/sh

    # signal window manager to update volume bar
    signal() {
    pkill -RTMIN+1 i3blocks
    }

    # change after your setup
    CARD='0'
    MIXERS="Master Front Surround Center LFE"

    # get "muted" or "unmuted"
    get_state() {
    res="unmuted"

    for m in $MIXERS; do
    if amixer -c $CARD get $m | grep '\[off\]' > /dev/null; then
    res="muted"
    break;
    fi
    done

    echo $res
    }

    # run for all playable mixers
    for_all_mixers() {
    for m in $MIXERS; do
    amixer -c $CARD set $m $1 > /dev/null
    done
    }

    # parse arg and run
    if [[ $1 == "+" ]]
    then
    amixer -c $CARD -q sset Master $2+
    signal
    elif [[ $1 == "-" ]]
    then
    amixer -c $CARD -q sset Master $2-
    signal

    elif [[ $1 == "mute" ]]
    then
    amixer -c $CARD set Master mute > /dev/null
    signal

    elif [[ $1 == "unmute" ]]
    then
    for_all_mixers "unmute"
    signal

    elif [[ $1 == "toggle" ]]
    then
    state=`get_state`
    if [ "$state" == "muted" ]; then
    for_all_mixers "unmute"
    else
    amixer -c $CARD set Master mute > /dev/null
    fi
    signal

    elif [[ $1 == "show" ]]
    then
    amixer -c $CARD get Master
    signal

    else
    echo "usage: $0 <show | toggle | mute | unmute | +/- [0-9]+>"
    fi