AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 12766
Accepted
Lincoln
Lincoln
Asked: 2010-11-12 16:11:25 +0800 CST2010-11-12 16:11:25 +0800 CST 2010-11-12 16:11:25 +0800 CST

通过命令行调整音量,以便弹出音量通知

  • 772

有没有办法通过命令行调整系统音量,以便仍然显示默认音量弹出窗口(按笔记本上的媒体键时弹出的那个)。

我的遥控器需要这个。它将使用 lircrc 文件和 irexec 运行。

command-line multimedia remote lirc
  • 5 5 个回答
  • 9901 Views

5 个回答

  • Voted
  1. Best Answer
    mgunes
    2010-11-12T16:54:29+08:002010-11-12T16:54:29+08:00

    安装xdotool包,然后尝试发出

    xdotool key XF86AudioLowerVolume
    

    和

    xdotool key XF86AudioRaiseVolume
    
    • 17
  2. htorque
    2010-11-12T17:04:59+08:002010-11-12T17:04:59+08:00

    您可以将快捷方式绑定到我在 Arch 论坛中找到的此脚本(需要软件包libnotify-bin):

    #!/bin/sh
    
    usage="usage: $0 -c {up|down|mute} [-i increment] [-m mixer]"
    command=
    increment=5%
    mixer=Master
    
    while getopts i:m:h o
    do case "$o" in
        i) increment=$OPTARG;;
        m) mixer=$OPTARG;;
        h) echo "$usage"; exit 0;;
        ?) echo "$usage"; exit 0;;
    esac
    done
    
    shift $(($OPTIND - 1))
    command=$1
    
    if [ "$command" = "" ]; then
        echo "usage: $0 {up|down|mute} [increment]"
        exit 0;
    fi
    
    display_volume=0
    
    if [ "$command" = "up" ]; then
        display_volume=$(amixer set $mixer $increment+ unmute | grep -m 1 "%]" | cut -d "[" -f2|cut -d "%" -f1)
    fi
    
    if [ "$command" = "down" ]; then
        display_volume=$(amixer set $mixer $increment- unmute | grep -m 1 "%]" | cut -d "[" -f2|cut -d "%" -f1)
    fi
    
    icon_name=""
    
    if [ "$command" = "mute" ]; then
        if amixer get Master | grep "\[on\]"; then
            display_volume=0
            icon_name="notification-audio-volume-muted"
            amixer set $mixer mute
        else
            display_volume=$(amixer set $mixer unmute | grep -m 1 "%]" | cut -d "[" -f2|cut -d "%" -f1)
        fi
    fi
    
    if [ "$icon_name" = "" ]; then
        if [ "$display_volume" = "0" ]; then
            icon_name="notification-audio-volume-off"
        elif [ "$display_volume" -lt "33" ]; then
            icon_name="notification-audio-volume-low"
        elif [ "$display_volume" -lt "67" ]; then
            icon_name="notification-audio-volume-medium"
        else
            icon_name="notification-audio-volume-high"
        fi
    fi
    notify-send " " -i $icon_name -h int:value:$display_volume -h string:synchronous:volume
    

    似乎在 Ubuntu 10.10 中运行良好。

    • 3
  3. dessert
    2017-09-28T23:22:41+08:002017-09-28T23:22:41+08:00

    控制音量

    您可以amixer用来控制音量,例如

    amixer set 'Master' 50%
    amixer set 'Master' 10%+
    amixer set 'Master' 2dB-
    

    您可能需要使用例如-c 1第二个声卡设置声卡,请参阅man amixer。

    播放声音

    可以使用类似aplay或的播放器播放声音paplay,例如

    paplay /usr/share/sounds/freedesktop/stereo/audio-volume-change.oga
    

    您可能想看看这个问题:我在哪里可以找到系统声音?

    显示屏幕通知

    您可以使用 X 屏幕显示库 XOSD 重现屏幕通知。调用该包xosd-bin并使用该命令osd_cat在屏幕上显示文本、状态栏等。

    osd_cat -b percentage -P 20 -T Status: -f "-adobe-helvetica-bold-*-*--34-*-*-*-*"
    

    显示

    在此处输入图像描述

    有关选项和示例以及更多信息,请参阅此德语 wiki 页面man osd_cat。

    • 2
  4. wjandrea
    2017-09-29T18:16:14+08:002017-09-29T18:16:14+08:00

    这是发布的脚本 htorque的改进版本。

    它在 14.04 对我有用。让我知道它是否适用于 16.04 或更高版本。

    它需要libnotify-bin安装。

    #!/bin/sh
    # Adjust the volume, play a sound, and show a notification.
    #
    # Replacement for default Ubuntu volume adjustment behaviour.
    #
    # Based on https://askubuntu.com/a/12769/301745
    
    command=""
    device="pulse"
    display_volume=0
    icon_name="error"
    increment=5
    mixer="Master"
    usage="usage: $0 [-d device] [-i increment] [-m mixer] (up|down|mute)"
    
    # For compatibility with SSH sessions.
    export DISPLAY=:0
    
    _amixer(){
        # amixer alias
        local set_get="$1"
        shift
        amixer -D "$device" "$set_get" "$mixer" "$@"
    }
    
    _get_display_volume(){
        # grep alias
        grep -Pom 1 '(?<=\[)[0-9]+(?=%\])'
    }
    
    while getopts d:hi:m: opt; do
        case "$opt" in
            d)
                device="$OPTARG"
                ;;
            h)
                echo "$usage"
                exit 0
                ;;
            i)
                increment="$OPTARG"
                ;;
            m)
                mixer="$OPTARG"
                ;;
            ?)
                echo "$usage"
                exit 1
                ;;
        esac
    done
    
    shift "$(($OPTIND - 1))"
    command="$1"
    
    case "$command" in
        down)
            display_volume="$(
                _amixer set "$increment%-" unmute |
                    _get_display_volume
                )"
            ;;
        mute)
            if _amixer get | grep -q "\[on\]"; then
                display_volume=0
                icon_name="notification-audio-volume-muted"
                _amixer set mute > /dev/null
            else
                display_volume="$(
                    _amixer set unmute |
                        _get_display_volume
                    )"
            fi
            ;;
        up)
            display_volume="$(
                _amixer set "$increment%+" unmute |
                    _get_display_volume
                )"
            ;;
        *)
            echo "$usage"
            exit 1
            ;;
    esac
    
    if [ "$icon_name" = "error" ]; then
        if [ "$display_volume" = "0" ]; then
            icon_name="notification-audio-volume-off"
        elif [ "$display_volume" -lt "33" ]; then
            icon_name="notification-audio-volume-low"
        elif [ "$display_volume" -lt "67" ]; then
            icon_name="notification-audio-volume-medium"
        else
            icon_name="notification-audio-volume-high"
        fi
    
        # In a subshell in the background to minimize latency.
        ( canberra-gtk-play --id=audio-volume-change & )
    fi
    
    notify-send "Volume: $display_volume%" -i "$icon_name" -h "string:synchronous:volume" -h "int:value:$display_volume"
    
    • 1
  5. Jakob
    2012-02-16T07:11:09+08:002012-02-16T07:11:09+08:00

    我安装了 xmacro 并将以下行添加到.lircrc:

    begin
            prog = irexec
            button = KEY_VOLUMEUP
            repeat = 1
            delay = 2
            config = echo KeyStrPress XF86AudioRaiseVolume KeyStrRelease XF86AudioRaiseVolume | xmacroplay $DISPLAY
    end
    begin
            prog = irexec
            button = KEY_VOLUMEDOWN
            repeat = 1
            delay = 2
            config = echo KeyStrPress XF86AudioLowerVolume KeyStrRelease XF86AudioLowerVolume | xmacroplay $DISPLAY
    end
    begin
            prog = irexec
            button = KEY_MUTE
            config = echo KeyStrPress XF86AudioMute KeyStrRelease XF86AudioMute | xmacroplay $DISPLAY
    end
    
    • 0

相关问题

  • 如何从命令行刻录双层 dvd iso

  • 如何从命令行判断机器是否需要重新启动?

  • Ubuntu 和交互式媒体安装

  • 文件权限如何工作?文件权限用户和组

  • 如何在 Vim 中启用全彩支持?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何安装 .run 文件?

    • 7 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    如何获得 CPU 温度?

    • 21 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Marko Smith

    如何使用命令行将用户添加为新的 sudoer?

    • 7 个回答
  • Marko Smith

    更改文件夹权限和所有权

    • 9 个回答
  • Marko Smith

    你如何重新启动Apache?

    • 13 个回答
  • Marko Smith

    如何卸载软件?

    • 11 个回答
  • Marko Smith

    如何删除 PPA?

    • 26 个回答
  • Martin Hope
    NES 如何启用或禁用服务? 2010-12-30 13:03:32 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    Olivier Lalonde 如何在结束 ssh 会话后保持进程运行? 2010-10-22 04:09:13 +0800 CST
  • Martin Hope
    David B 如何使用命令行将用户添加为新的 sudoer? 2010-10-16 04:02:45 +0800 CST
  • Martin Hope
    Hans 如何删除旧内核版本以清理启动菜单? 2010-08-21 19:37:01 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve