首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >无法在shell脚本中使用aplay播放声音

无法在shell脚本中使用aplay播放声音
EN

Stack Overflow用户
提问于 2022-02-26 15:39:08
回答 1查看 243关注 0票数 0

我的回购链接:电池通知器

这是我希望使用的shell脚本。我想得到电池通知。

但是,当我在全屏模式下看到视频时,它不会给我通知。因此,我添加了aplay来播放通知的声音。尽管如此,它还是不能用。

你甚至可以给我推荐一个更好的电池通知器。

我正在使用LinuxMintMate20.3。

下面是文件内容:

代码语言:javascript
运行
复制
#!/bin/bash
#please install acpi before using this ==> sudo apt install acpi
while true; do
    export DISPLAY=:0.0
    battery_level=$(acpi -b | grep -P -o '[0-9]+(?=%)')
    ac_adapter=$(acpi -a | cut -d' ' -f3 | cut -d- -f1)

    if on_ac_power; then                   #check if AC is plugged in
        if [ $battery_level -ge 95 ]; then #check if the battery level is over 90%
            notify-send -u critical "Please, kindly unplug your AC adapter" "Battery level: ${battery_level}%" -i battery-full-charged
            # sleep 300
        elif [ $battery_level -le 20 ]; then
            notify-send -u critical "Thank you!!!" "You did an excellent job, Keep it up." -i battery-caution-charging
            sleep 300 #sleep as charging upto 20 take 15 min max
            # break
        fi
        #if [ $ac_adapter -eq "off" ]; then
        #    notify-send -u critical "AC Adapter" "The AC Adapter is off."
    #fi

    fi

    if [ "$ac_adapter" == "off" ]; then
        if [ $battery_level -le 20 ]; then #check if the battery level is over 90%
            notify-send -u critical "Please, kindly plug-in your AC adapter" "Battery level: ${battery_level}%" -i battery-caution
            # To get the sound notification
            aplay sounds/mixkit-wrong-answer-fail-notification-946.wav
            # break
            # sleep 180
        elif [ $battery_level -le 30 ]; then
            notify-send -u critical "Charge it man its ${battery_level}%" -i battery-caution

            # To get the sound notification
            aplay sounds/mixkit-bell-notification-933.wav
            # break
            sleep 200
        elif [ $battery_level == 40 ]; then
            notify-send -u critical "Its ${battery_level}%" -i face-angel
            # To get the sound notification
            aplay sounds/mixkit-bell-notification-933.wav

            # break
            sleep 180
        elif [ $battery_level -ge 95 ]; then
            notify-send -u critical "Thank you!!!" "You did an excellent job,Now remove the charger." -i face-angel
            # To get the sound notification
            aplay sounds/mixkit-melodical-flute-music-notification-2310.wav
            sleep 90 # sleep as charging is above 95
        fi
  
  fi
    sleep 5 #wait for 300 seconds before checking again

done

#to add this to startup application ==> https://www.simplified.guide/gnome/automatically-run-program-on-startup
EN

Stack Overflow用户

回答已采纳

发布于 2022-03-05 07:19:52

我想出了声音文件夹的位置不对。因此,我在~/music/BatteryNotifySound复制了声音文件夹,并反映了上述脚本中的更改及其完成。

票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71277994

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档