8

I have a very low timing on sleep mode. I like it this way... (it's like 20 minutes).

After I idle for 20 minutes my system will go into auto sleep mode and I need to press the keyboard to reactivate.

Is there a way to make a noise/bleep when Ubuntu is about to go into sleep mode?

I do receive a notification warning with text but I'm frequently not looking at the screen.

3

As the NotifyOSD team is taking its time to add sound to notifications, here's a script that will accomplish the same thing good enough for your particular use case.
(It'll only notify you with a beep when the system goes to sleep, no beep on all notifications I'm afraid...)

  1. Copy-paste the following script:

    #!/bin/bash
    
    #
    # This script plays a sound if the system is going into hibernation/sleep mode
    # as an answer to http://askubuntu.com/questions/552999/how-to-warn-noise-bleep-when-ubuntu-is-about-to-go-into-sleep-mode/553026
    # Original script name: /etc/pm/sleep.d/sleep-beep
    #
    
    # Copyright (c) Fabby 2015
    
    # This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
    # This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. See the GNU General Public License for more details.
    # You DID NOT receive a copy of the GNU General Public License along with this program as the license is bigger then this program.
    # Therefore, see http://www.gnu.org/licenses/ for more details.
    
    case $1 in
      suspend|suspend_hybrid|hibernate)
        notify-send --urgency=NORMAL --icon=face-tired "Going to sleep"
        ogg123 /usr/share/sounds/ubuntu/stereo/desktop-login.ogg
      ;;
    
      resume|thaw)
        # No need to do anything here, but easy to add if needed
      ;;
    
    esac
    
  2. into gedit

  3. Save it as sleep-beep in your Documents directory
  4. Press Ctrl+Alt+T to go to a terminal
  5. Make the script executable and then copy it to the right directory:

    sudo chmod +x ~/Documents/sleep-beep
    sudo cp ~/Documents/sleep-beep /etc/pm/sleep.d/sleep-beep
    
  6. As it needs to play ogg files from the command-line, it also needs:

    sudo apt-get install vorbis-tools
    

Done! :-)

  • What does that resume|thaw do? And where does the script get the $1 from? – Ashhar Hasan Dec 6 '15 at 22:41
  • @AshharHasan: You stalking me??? ;-) It gets it from another script... :D – Fabby Dec 6 '15 at 23:05
  • 1
    I'll read some documentation now I guess. Just saw this question and seemed like something I would want. – Ashhar Hasan Dec 6 '15 at 23:08
  • Yes! RTFM is always good! ;-) But upvoting is even better! @AshharHasan – Fabby Dec 6 '15 at 23:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.