Take the 2-minute tour ×

My laptop unplugged stands 1 minute. Previous week my laptop cable, started not connecting good with the laptop.

I would like to play a certain sound everytime it gets's unplugged so I can hurry and connect them good.. Anyone?

share|improve this question
add comment

3 Answers

#!/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")

    timer = Timer(300.0,battery_check)

if __name__ == "__main__": battery_check()

Download here.

share|improve this answer
add comment

You can use 'cuttlefish' and 'vlc' (for example) from the Ubuntu-Software-Centre. With this fine little application you can use diffrent situations as a trigger for specific actions to be carried out.

Like for you it would be:

start cuttlefish

  • create new 'rule'
    1. choose 'activate by stimulus'
    2. choose stimulus -> hardware -> 'power cable unplugged'
    3. then on 'reactions' tab choose 'start application (advanced mode)'
    4. choose cvlc (need to have vlc installed) as executable
    5. type the path to the desired sound (should be short) into the parameter field

Now your sound should be played every time you unplug your power cable.

share|improve this answer
add comment

As explained in this answer, you have to:

  1. cd into your home folder and create the directory .local/share/sounds:

    cd && mkdir -p .local/share/sounds
  2. cd into the newly created directory:

    cd .local/share/sounds
  3. place the desired sound inside the directory, renaming it as power-unplug.wav (for example in this way):

    ln -s /usr/share/sounds/alsa/Noise.wav power-unplug.wav
  4. test the event with:

    canberra-gtk-play -i power-unplug

I suppose that, at this point, you have to logout and log back in to have the event work properly. Try it and see if it works. You can find more events and sound names here.

share|improve this answer
add comment

Your Answer


