0

My computer speakers make a horrible sound while shutting down and I keep forgetting to turn them off before shutdown. I would like to prevent this with a "just in time" reminder. Something like a popup window that also delays shut down until I click a confirmation button would be great.

Elder Geek
  • 36,023
  • 25
  • 98
  • 183
matiascelasco
  • 143
  • 2
  • 2
  • 9
  • Standard Ubuntu and most of the derivatives with other DEs already do that by default. –  Aug 17 '17 at 08:34
  • By "horrible sound" do you mean PC Speaker Beep? If so this might help: https://askubuntu.com/questions/829258/turn-off-motherboard-pc-speaker-beep-in-ubuntu-16-04-regression – WinEunuuchs2Unix Aug 17 '17 at 11:03

2 Answers2

1

To display a message before halting, just follow these steps:

  1. Write a script containing the commands you want to be executed, e. g.:

    #!/bin/bash
    # for zenity it might be necessary to set the DISPLAY variable first with the following line:
    # DISPLAY=":0.0"
    zenity --warning
    
  2. save the script wherever you want, I use ~/scripts/myscript as an example here

  3. make it executable with

    sudo chmod +x ~/scripts/myscript
    
  4. link it to the shutdown directory using

    sudo ln -s ~/scripts/myscript /etc/rc0.d/k01zenitywarning
    

The script will be executed the next time you shut down. To execute it alsoon reboot, additionally link it to /etc/rc6.d/ with sudo ln -s ~/scripts/myscript /etc/rc6.d/k01zenitywarning.

This does what you asked for, however I also really like omid abc's approach to solve the problem – instead of manually turn off the speakers every time just mute the sound using his command (replace the zenity line in the script for that).

Edit – simpler approach

An even simpler way is provided by the upstart package, after installing it just save the following script in ~/.init/onshutdown.conf

start on starting rc RUNLEVEL=0
task
script
 # for zenity it might be necessary to set the DISPLAY variable first with the following line:
 # DISPLAY=":0.0"
 zenity --warning
end script

Again, zenity --warning can be replaced by any command(s). This script doesn't need to be made executable, just save it and you're done. For more information about upstart see man 5 init.

dessert
  • 39,982
0

A solution for your problem is to mute volume before shut down. Write this script in /etc/rc0.d:

#!/bin/bash    
amixer set Master mute

be sure to make this script executable by using sudo chmod +x myscript

Note that the script is directory will be executed in alphabetical order.the name of your script must begin with k99 to run at a right time

By using this solution when you shoutdown your system it will automatically mute volume