简体   繁体   English

在bash脚本中设置系统卷(在linux中)

[英]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. 我需要在bash脚本中设置系统卷,但我不知道如何执行此操作。 Should I use alsactl ? 我应该使用alsactl吗? Are there some values in /proc or /sys that I could use? 我可以使用/proc/sys中的某些值吗?

You should use the amixer tool. 你应该使用amixer工具。

Run amixer without parameters to get a list of mixer controls. 运行不带参数的amixer以获取混音器控件列表。
Use commands like this: 使用这样的命令:

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

You can also use pactl . 你也可以使用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. 特别是, pactl set-sink-mute 0 0 amixer set Master unmute命令在我的计算机上工作,其中amixer set Master unmute没有。

I've got a nice vol script in my ~/bin to help me do the trick ... 我的〜/ bin中有一个很棒的vol脚本来帮助我做到这一点......

#!/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. 如果你没有安装Xdialog一个简单的echo $ {VOL [3]}会给你一些alsamixer反馈。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM