How to play a sound when laptop gets unplugged?

Solution 1:

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.