笔记本电脑拔掉电源后如何播放声音?

Leo*_*nos 7 battery notification sound

我的笔记本电脑拔掉电源后停留 1 分钟。上周我的笔记本电脑电缆开始与笔记本电脑连接不良。

我想在每次拔掉插头时播放某种声音,这样我就可以赶紧将它们连接好。有人吗?

Avi*_*vio 4

正如此答案中所解释的,您必须:

  1. cd进入您的主文件夹并创建目录.local/share/sounds

    cd && mkdir -p .local/share/sounds
    
    Run Code Online (Sandbox Code Playgroud)
  2. cd进入新创建的目录:

    cd .local/share/sounds
    
    Run Code Online (Sandbox Code Playgroud)
  3. 将所需的声音放入目录中,将其重命名为power-unplug.wav(例如以这种方式):

    ln -s /usr/share/sounds/alsa/Noise.wav power-unplug.wav
    
    Run Code Online (Sandbox Code Playgroud)
  4. 使用以下命令测试事件:

    canberra-gtk-play -i power-unplug
    
    Run Code Online (Sandbox Code Playgroud)

我想,此时,您必须注销并重新登录才能使活动正常进行。尝试一下,看看是否有效。您可以在此处找到更多事件和声音名称。


小智 -1

#!/usr/bin/env python

import commands
import pynotify
from threading import Timer


def battery_check():

    rem = float(commands.getoutput("grep \"^remaining capacity\" /proc/acpi/battery/BAT0/state | awk '{ print $3 }'"))
    full = float(commands.getoutput("grep \"^last full capacity\" /proc/acpi/battery/BAT0/info | awk '{ print $4 }'"))
    state = commands.getoutput("grep \"^charging state\" /proc/acpi/battery/BAT0/state | awk '{ print $3 }'")

    percentage = int((rem/full) * 100)

    if state == "discharging":
        pynotify.init("Battery Alert!")
        notification = pynotify.Notification("Battery "+state,str(percentage)+"%","/usr/share/icons/gnome/32x32/status/battery-low.png")
        notification.show()

    timer = Timer(300.0,battery_check)
    timer.start()

if __name__ == "__main__": battery_check()
Run Code Online (Sandbox Code Playgroud)

在这里下载。