You are not logged in.
my main mixer control (PCM) is unable to use the 'toggle' function for some reason i've never investigated, so i modified the script to set the volume to 0, then back to the previous volume.
#!/bin/bash
#
# dvolbar - OSD Volume utility
#
#Customize this stuff
IF="PCM" # audio channel: Master|PCM
SECS="1" # sleep $SECS
BG="#111111" # background colour of window
FG="#eeeeee" # foreground colour of text/icon
BAR_FG="#ffffff" # foreground colour of volume bar
BAR_BG="#777777" # background colour of volume bar
XPOS="550" # horizontal positioning
YPOS="400" # vertical positioning
HEIGHT="30" # window height
WIDTH="250" # window width
BAR_WIDTH="165" # width of volume bar
FONT="-*-terminus-medium-r-*-*-14-*-*-*-*-*-*-*"
ICON=~/.icons/dzen/xbm8x8/spkr_01.xbm
MUTE_ICON=~/.icons/dzen/xbm8x8/spkr_02.xbm
#Probably do not customize
PIPE="/tmp/dvolpipe"
err() {
echo "$1"
exit 1
}
usage() {
echo "usage: dvol [option] [argument]"
echo
echo "Options:"
echo " -i, --increase - increase volume by \`argument'"
echo " -d, --decrease - decrease volume by \`argument'"
echo " -t, --toggle - toggle mute on and off"
echo " -h, --help - display this"
exit
}
mute_toggle() {
VOL_FILE="/tmp/cur_vol"
CUR_VOL=$(amixer get "$IF" | gawk '/Right.+/ {gsub("\\[","", $5);gsub("%\\]", "", $5);printf("%s",$5)}')
if [[ $CUR_VOL -gt 0 ]]; then
echo $CUR_VOL > $VOL_FILE
amixer -q set "$IF" 0%
ICON=$MUTE_ICON
else
VOL=$(cat $VOL_FILE)
amixer -q set "$IF" ${VOL}%
rm -f $VOL_FILE
fi
}
#Argument Parsing
case "$1" in
'-i'|'--increase')
[ -z "$2" ] && err "No argument specified for increase."
[ -n "$(tr -d [0-9] <<<$2)" ] && err "The argument needs to be an integer."
AMIXARG="${2}%+"
;;
'-d'|'--decrease')
[ -z "$2" ] && err "No argument specified for decrease."
[ -n "$(tr -d [0-9] <<<$2)" ] && err "The argument needs to be an integer."
AMIXARG="${2}%-"
;;
'-t'|'--toggle')
mute_toggle
MUTE=1
;;
''|'-h'|'--help')
usage
;;
*)
err "Unrecognized option \`$1', see dvol --help"
;;
esac
#Actual volume changing (readability low)
if [[ -z $MUTE ]]; then
AMIXOUT="$(amixer set "$IF" "$AMIXARG" | tail -n 1)"
VOL="$(cut -d '[' -f 2 <<<"$AMIXOUT" | sed 's/%.*//g')"
fi
#Using named pipe to determine whether previous call still exists
#Also prevents multiple volume bar instances
if [ ! -e "$PIPE" ]; then
mkfifo "$PIPE"
(dzen2 -tw "$WIDTH" -h "$HEIGHT" -x "$XPOS" -y "$YPOS" -fn "$FONT" -bg "$BG" -fg "$FG" < "$PIPE"
rm -f "$PIPE") &
fi
#Feed the pipe!
(echo "$VOL" | gdbar -l "^i(${ICON})" -fg "$BAR_FG" -bg "$BAR_BG" -w "$BAR_WIDTH" ; sleep "$SECS") > "$PIPE"
Offline
hya guys
using paldepind example script and it works like a charm apart for the fact i get no % text just the icon and bar..i have terminus installed and dzen2-xft-xpm-xinerama-svn ..any idea why
thx
zeltaj
Offline
using paldepind example script and it works like a charm apart for the fact i get no % text just the icon and bar..i have terminus installed and dzen2-xft-xpm-xinerama-svn ..any idea why
Yeah, you're using svn. The svn version only shows the bar, while the stable release shows percentage+bar. This is why I keep an old gdbar around, only dzen2 itself is from svn, so I get xft. That, and the old gdbar has a conky-style bar.
Offline
I have modified the script so as to handle pulseaudio.
The reference scripts are from the above messages and
http://crunchbanglinux.org/forums/topic … edia-keys/
Also I apologize for the color combination. They were for testing purpose only. Change them to suit your need.:)
#!/bin/bash
#
# filename: pulsevolbar.sh
# Usage:
# pulsevolbar.sh <increase/decrease/mute>
#
#
#Customize this stuff
SECS="1" # sleep $SECS
BG="#8E35EF" # background colour of window
FG="#FFFF00" # foreground colour of text/icon
BAR_FG="#F52887" # foreground colour of volume bar
BAR_BG="#41A317" # background colour of volume bar
XPOS="705" # horizontal positioning
YPOS="800" # vertical positioning
HEIGHT="30" # window height
WIDTH="250" # window width
BAR_WIDTH="150" # width of volume bar
ICON=~/.pulse/dzen_icons/vol-hi.xbm
FONT="-*-terminus-medium-r-*-*-14-*-*-*-*-*-*-*"
ICON_VOL=~/.pulse/dzen_icons/vol-hi.xbm
ICON_VOL_MUTE=~/.pulse/dzen_icons/vol-mute.xbm
ICON=$ICON_VOL
# No need to customize this variable
PIPE="/tmp/pulesvolpipe"
set_volume()
{
CURVOL=$1
pactl set-sink-volume 0 $CURVOL
echo $CURVOL > ~/.pulse/volume # Write the new volume to disk to be read the next time the script is run.
}
#### Create ~/.pulse/mute if not exists
ls ~/.pulse/mute &> /dev/null
if [[ $? != 0 ]]
then
echo "false" > ~/.pulse/mute
fi
####Create ~/.pulse/volume if not exists
ls ~/.pulse/volume &> /dev/null
if [[ $? != 0 ]]
then
echo "65536" > ~/.pulse/volume
fi
CURVOL=`cat ~/.pulse/volume` # Reads in the current volume
MUTE=`cat ~/.pulse/mute` # Reads mute state
if [[ $MUTE == "true" ]] # Sets the icon to mute_icon as the increase or decrease will not make speaker speak
then
ICON=$ICON_VOL_MUTE
fi
if [[ $1 == "increase" ]]
then
CURVOL=$(($CURVOL + 3277)) # 3277 is 5% of the total volume, you can change this to suit your needs.
if [[ $CURVOL -ge 65536 ]]
then
CURVOL=65536
fi
set_volume $CURVOL
elif [[ $1 == "decrease" ]]
then
CURVOL=$(($CURVOL - 3277))
if [[ $CURVOL -le 0 ]]
then
CURVOL=0
fi
set_volume $CURVOL
elif [[ $1 == "mute" ]]
then
if [[ $MUTE == "false" ]]
then
pactl set-sink-mute 0 1
echo "true" > ~/.pulse/mute
ICON=$ICON_VOL_MUTE
else
pactl set-sink-mute 0 0
echo "false" > ~/.pulse/mute
ICON=$ICON_VOL
fi
fi
# showing in dzen2
if [ ! -e "$PIPE" ];
# if pipe file does not exists
then
mkfifo "$PIPE"
(dzen2 -tw "$WIDTH" -h "$HEIGHT" -x "$XPOS" -y "$YPOS" -fn "$FONT" -bg "$BG" -fg "$FG" < "$PIPE"
rm -f "$PIPE") &
fi
# feed the pipe
(echo $[$CURVOL * 100 / 65536]| dzen2-gdbar -l "^i(${ICON})" -fg "$BAR_FG" -bg "$BAR_BG" -w "$BAR_WIDTH" ; sleep "$SECS" ) > "$PIPE"
Offline
Hi guys,
Very nice script ! But I have a problem with the files .pulse/volume & .pulse/mute. If you change something in pulseaudio via mpd for exemple, the volume or muted state are never write in the files. So why not grab the volume and the muted state in pacmd ?
For the volume :
# Get current volume. return a %
function get_volume(){
MIXER=$(pacmd list-sinks 0 | grep -i "volume: 0:")
echo $MIXER | cut -d ' ' -f 3 | cut -d '%' -f 1
}
# For the real volume, you have to * 65536 / 100
VOL=$(get_volume)
CURVOL=$[$VOL * 65536 / 100]
For the muted state :
# Get muted ? return yes or no
function get_muted(){
MUTED=$(pacmd list-sinks 0 | grep muted | cut -d ' ' -f 2)
echo $MUTED
}
MUTE=$(get_muted) # Reads mute state
And you juste have to change "false" by "no" in
if [[ $MUTE == "false" ]]
Thx for the original script, my xf86audio keys are happy now
Offline
I m pasting the new script with the recommended changes.
Also now the volume bar centers itself accordingly as per the resolution.
But the setting of volume through mpd still does not reflect as the script reads/sets the main output volume, but mpd sets/reads the application volume. (Correct me if I am wrong as I am new to pulseaudio)
#!/bin/bash
#
# filename: pulsevolbar.sh
# Usage:
# pulsevolbar.sh <increase/decrease/mute>
#
#
#Customize this stuff
SECS="1" # sleep $SECS
BG="#8E35EF" # background colour of window
FG="#FFFF00" # foreground colour of text/icon
BAR_FG="#F52887" # foreground colour of volume bar
BAR_BG="#41A317" # background colour of volume bar
HEIGHT="30" # window height
WIDTH="250" # window width
BAR_WIDTH="150" # width of volume bar
ICON=~/.pulse/dzen_icons/vol-hi.xbm
FONT="-*-terminus-medium-r-*-*-14-*-*-*-*-*-*-*"
ICON_VOL=~/.icons/dzen_icons/vol-hi.xbm
ICON_VOL_MUTE=~/.icons/dzen_icons/vol-mute.xbm
ICON=$ICON_VOL
PULSE_MAX_VOL=65536
# No need to customize this variable
PIPE="/tmp/pulesvolpipe"
# Lets find the appropriate positioning for the volume bar
XRES=`xdpyinfo|grep 'dimensions:'|awk '{print $2}'|cut -dx -f1`
XPOS=$[$XRES / 2 - $WIDTH / 2] # horizontal positioning
YRES=`xdpyinfo|grep 'dimensions:'|awk '{print $2}'|cut -dx -f2`
YPOS=$[$YRES * 4 / 5] # vertical positioning
# Sets the desired volume
function set_volume()
{
CURVOL=$1
pactl set-sink-volume 0 $CURVOL
}
# Gets the current volume
function get_volume()
{
MIXER=$(pacmd list-sinks 0 | grep -i "volume: 0:")
echo $MIXER | cut -d ' ' -f 3 | cut -d '%' -f 1
}
# Get muted ? returns yes or no
function get_muted()
{
MUTED=$(pacmd list-sinks 0 | grep muted | cut -d ' ' -f 2)
echo $MUTED
}
VOL=$(get_volume)
CURVOL=$[$VOL * $PULSE_MAX_VOL / 100 ]
MUTE=$(get_muted) # Reads mute state
if [[ $MUTE == "yes" ]] # Sets the icon to mute_icon as the increase or decrease will not make speaker speak
then
ICON=$ICON_VOL_MUTE
fi
if [[ $1 == "increase" ]]
then
CURVOL=$(($CURVOL + 3277)) # 3277 is 5% of the total volume, you can change this to suit your needs.
if [[ $CURVOL -ge $PULSE_MAX_VOL ]]
then
CURVOL=$PULSE_MAX_VOL
fi
set_volume $CURVOL
elif [[ $1 == "decrease" ]]
then
CURVOL=$(($CURVOL - 3277))
if [[ $CURVOL -le 0 ]]
then
CURVOL=0
fi
set_volume $CURVOL
elif [[ $1 == "mute" ]]
then
if [[ $MUTE == "no" ]]
then
pactl set-sink-mute 0 1
ICON=$ICON_VOL_MUTE
else
pactl set-sink-mute 0 0
ICON=$ICON_VOL
fi
fi
# showing in dzen2
if [ ! -e "$PIPE" ];
# if pipe file does not exists
then
mkfifo "$PIPE"
(dzen2 -tw "$WIDTH" -h "$HEIGHT" -x "$XPOS" -y "$YPOS" -fn "$FONT" -bg "$BG" -fg "$FG" < "$PIPE"
rm -f "$PIPE") &
fi
# feed the pipe
(echo $[$CURVOL * 100 / $PULSE_MAX_VOL]| dzen2-gdbar -l "^i(${ICON})" -fg "$BAR_FG" -bg "$BAR_BG" -w "$BAR_WIDTH" ; sleep "$SECS" ) > "$PIPE"
PS: Man, the fifo thing was elegent. Kudos to the original author. I learned a new thing. (for me atleast)
Offline
Hey, can someone post the content of his ~/.config/openbox/rc.xml, because I have problem making my multimedia keys work =/
Offline
Using this with PekWM. Works GREAT.
- [ My Blog ] | [ AUR Packages ] | [ My deviantART ] | [ screenFetch ] | [ SilverIRC ] -
Offline
hey guys! how did you find out which were your keys? I'm using dwm/monsterwm. I remember I used something like XF86audioMute or something like that, for the key's name in the config file.
Offline
They're always the same: XF86AudioRaiseVolume, XF86AudioLowerVolume, XF86AudioMute
Offline
hey guys! how did you find out which were your keys? I'm using dwm/monsterwm. I remember I used something like XF86audioMute or something like that, for the key's name in the config file.
The command `xev` could help you find that out, as well.
- [ My Blog ] | [ AUR Packages ] | [ My deviantART ] | [ screenFetch ] | [ SilverIRC ] -
Offline
I m pasting the new script with the recommended changes.
Also now the volume bar centers itself accordingly as per the resolution.
But the setting of volume through mpd still does not reflect as the script reads/sets the main output volume, but mpd sets/reads the application volume. (Correct me if I am wrong as I am new to pulseaudio)
I dont get how this works. It does change volume, but the dzen stuff is not working. I only get a completely purple rectangle, which always looks the same.
Also what is "dzen2-gdbar"?
➜ ~ ./pulsevolbar.sh increase
./pulsevolbar.sh: line 100: dzen2-gdbar: command not found
Last edited by Rasi (2012-04-01 08:43:46)
He hoped and prayed that there wasn't an afterlife. Then he realized there was a contradiction involved here and merely hoped that there wasn't an afterlife.
Douglas Adams
Offline
@Rasi
To use gdbar you have to install https://aur.archlinux.org/packages.php?ID=14470
Offline
where are the dzen colors?
Offline
where are the dzen colors?
Offline
Mhh, I get an error but it shouldn't be that critical, what might cause this? Dvol script still works.
[~] dvol lower
/home/shn/bin/center_rect: line 30: printf: /home/shn/bin/center_rect: invalid number
[~]
Last edited by Shinryuu (2012-09-23 15:07:30)
Offline
It is rare, but multiple instances of dzen2 can reach that part of
the code (producing a blank window):
mkfifo "$TMP_FIFO"
(dzen2 -h "$bar_height" -w "$bar_width" $xy_pos -fn "$bar_font" -bg "$bar_bg" -fg "$bar_fg" < "$TMP_FIFO"
rm "$TMP_FIFO") &
This should be replaced with:
if mkfifo "$TMP_FIFO" ; then
(dzen2 -h "$bar_height" -w "$bar_width" $xy_pos -fn "$bar_font" -bg "$bar_bg" -fg "$bar_fg" < "$TMP_FIFO"
rm "$TMP_FIFO") &
fi
(This has nothing to do with Shinryuu's issue.)
Last edited by bloom (2012-09-27 15:41:12)
Offline
Ah, I didn't notice your question. It seems I solved my issue by fiddling with center_rect where I changed "xoffset and yoffset" to simple pixels numbers.
xoffset=1580
yoffset=52
sres (laptop)
1366x768
sres (pc)
1920x1080
Offline
Offline
Sure and here's the results.
laptop
533 242
533 242
pc
810 346
810 346
I fiddled with center_rect a little bit more and I found this out, I typed "xoffset" "yoffset" lines again and the error is now gone with my laptop, maybe I had an extra empty space/line?
Last edited by Shinryuu (2012-09-28 04:14:44)
Offline