Dan-Simon Myrland
Dan-Simon Myrland

Reputation: 337

Setting system volume in a bash script (in linux)

I need to set the system volume in a bash script, but I have no idea how to do this. Should I use alsactl? Are there some values in /proc or /sys that I could use?

Upvotes: 3

Views: 5941

Answers (3)

user7449824
user7449824

Reputation: 18

I've got a nice vol script in my ~/bin to help me do the trick ...

#!/bin/sh

export XDIALOG_NO_GMSGS=1

case ${1} in
    +|-) VOL=( $(amixer set Master 10dB${1} |tail -1|tr -d "[]") )
        Xdialog --no-buttons --title "Vol" --infobox ${VOL[3]} 50x30+32+32 ;;
    *[0-9]) VOL=( $(amixer set Master "${1}%" |tail -1|tr -d "[]") )
        Xdialog --no-buttons --title "Vol" --infobox ${VOL[3]} 50x30+32+32 ;;
    *) printf "Usage: vol [+]|[-]|[0-100]\n" >&2 ;;
esac

If you don't have Xdialog installed a simple echo ${VOL[3]} will give you some alsamixer feedback.

Upvotes: 0

chenjesu
chenjesu

Reputation: 754

You can also use pactl.

pactl set-sink-volume 0 60%  # set absolute
pactl set-sink-volume 0 +10% # set relative
pactl set-sink-mute 0 0      # unmute

In particular, the pactl set-sink-mute 0 0 unmute command works on my computer where amixer set Master unmute doesn't.

Upvotes: 2

CL.
CL.

Reputation: 180060

You should use the amixer tool.

Run amixer without parameters to get a list of mixer controls.
Use commands like this:

amixer set Master 50%     # set absolute
amixer set Master 2dB+    # set relative
amixer set Master unmute

Upvotes: 5

Related Questions