You are not logged in.

#1 2016-01-31 19:08:46

awesome8x
Member
Registered: 2016-01-31
Posts: 7

Simple Volume and Brightness Notification Scripts for Hotkeys

Linux newb here. I don't like Ubuntu's notify-osd, so I decided to create my own scripts for volume and brightness notifications that replace the existing notification instead of creating a new one. I quickly found that I didn't have the bash knowledge to do this from scratch, but I accomplished it by using notify-send.sh and a script for volume notifications that I found on the Crunchbang forums that I can't for the life of me seem to find again. I don't have a working percent bar (if anybody wants to add that, feel free), but it has a text display of "Volume: %" and "Brightness: x%". In order to use these, replace /usr/bin/notify-send with the notify-send.sh link shared above. It replaced it seamlessly for me. Here are the scripts:

vol.sh (heavily modified version of script found on Crunchbang forums) (map volume up, down, and mute keys to "vol.sh up", "vol.sh down", and "vol.sh mute" respectively):

#!/bin/bash

showVol() {
    VOL="$(amixer get Master | egrep -o -m1 "[0-9]+%")"
    if test -e /tmp/vol-id ; then
        ARG="-r $(head -n 1 /tmp/vol-id)"
    else
        ARG=""
    fi
    if amixer get Master | grep -q off; then
        echo $(notify-send $ARG -p -u low "Muted") > /tmp/vol-id
    else
        echo $(notify-send $ARG -p -u low "Volume: $VOL") > /tmp/vol-id
    fi
}

volUp() {
    amixer -q set Master unmute
    amixer -q sset Master "2%+"
    
}
 
volDown() {
    amixer -q set Master unmute
    amixer -q sset Master "2%-"
}


# main part

case "$1" in
    "volup")
            volUp
            ;;
    "voldown")
            volDown
            ;;
    "mute")
            amixer -q set Master toggle
            ;;
    *)
            ;;
esac
showVol

bright.sh (lightly modified version of above script) (map brightness up and down keys to "bright.sh up" and "bright.sh down" respectively):

#!/bin/bash

showVol() {
    BRT="$(light)"
    BRT="$(echo "scale=1; $BRT/10" | bc)"
    BRT="$(printf "%.0f\n" $BRT)"
    BRT="$(echo "scale=0; $BRT*10" | bc)"
    if test -e /tmp/brt-id ; then
        ARG="-r $(head -n 1 /tmp/brt-id)"
    else
        ARG=""
    fi
    echo $(notify-send $ARG -p -u low "Brightness: $BRT%") > /tmp/brt-id
}

volUp() {
    light -A 10
}

volDown() {
    light -U 10
}


# main part

case "$1" in
    "up")
            volUp
            ;;
    "down")
            volDown
            ;;
    *)
            ;;
esac
showVol

Note that this relies on having Light (from AUR) and alsa-utils installed, but it should be easy enough to modify for use with xbacklight or other similar programs. Also, bc is necessary for brightness rounding. I hope this helps somebody! (Also, if somebody can track down that original volume script and clear my conscious a bit, please do)

EDIT: removed an unneeded modification to notify-send.sh

Last edited by awesome8x (2016-01-31 19:24:04)

Offline

Board footer

Powered by FluxBB