I want my laptop to wake up from suspended mode in the morning and alarm me to wake up using my mp3 file. How do I do it?
I tried apmsleep, but it doesn't work cause my PC doesnt have "suspend to RAM" feature in BIOS. What can I do? Thanks!
I want my laptop to wake up from suspended mode in the morning and alarm me to wake up using my mp3 file. How do I do it?
I tried apmsleep, but it doesn't work cause my PC doesnt have "suspend to RAM" feature in BIOS. What can I do? Thanks!
1.Basic alarm clock function
Entering suspend mode
for this solution, you need to enter suspend mode by running the script below. It makes the computer go into suspend mode and wakes you up at a (clock-) time, defined by you (in the script). playing your song.
Of course you can simply run the script manually to use it, but it is more convenient to make it available via a key combination, set in
System Settings > Keyboard > Shortcuts > Custom Shortcuts
.Set up
Paste the script below in an empty file, set the wake up (clock) time (in 1-24 hours, 1-60 minutes), set the path to your wake up song, and save it as
wakeup.py
.make the script executable
Set a key combination to run the script; open
System Preferences > Keyboard > Shortcuts > Custom Shortcuts
, add the commandand choose a key combination
The script needs administrator's privileges. To run it without having to enter the password, open the sudoers file:
add the line to the very bottom of the file:
Note that the sudoers file is an essential file; errors in the file possibly lead to serious problems, so be careful!
N.B.
gksu
:sudo apt-get install gksu
. In that case, the command to run the script isgksu /path/to/wakeup.py
, and you will be prompted for your password each time you run it.Now you can enter suspend mode with your key combination and you'll get woken by your wake up song.
2.Extended version including stop function when (any) key or mouse is hit
The differences between this one and the "basic" version is that in this one the alarm stops when any keystroke or mouse movement is detected (more convenient than stopping Rhythmbox on the computer when you just woke up), and that the alarm automatically exits after a defined period of time.
The setup is pretty much the same as the basic version, but
xprintidle
needs to be installed, to detect keystroke- or mouse movement events:The script:
Explanation
rtcwake
Both scripts are written around the
rtcwake
command, as explained here. The command can be used to put the computer into suspend and wake up after a defined amount of time (and optionally run a command after wake up). The-m disk
option is used, since OP mentioned his computer does not support "suspend to RAM" feature in BIOS. See alsoman rtcwake
.The stop function
The stop function works by a function that measures idle time every second while the song is playing, and remembers the last idle time. IF the last idle time exceeds the current one, it means a keystroke or mouse event has taken place, and Rhythmbox is killed.
If you can have your laptop connected to internet by a cable, you can try to use an other computer or smartphone to send a "magic packet" to it, and wake it up.
Look for "wake on lan" (WOL).
I had troubles running Jacob's python script, so I rewrote it in bash. Just download it, make it executable and edit variables accordingly.
A couple of things: alarm time is set via
date -d
. Some examples fromman date
:After wake up I use
vlc -L
to play some music in a loop. If your path is a folder, it will try to play files in it. That's what I do.Not sure if this is what you're looking for, but I just found a simple working 'alarm' that automatically wakes up from suspend mode:
The
-m freeze
option idles processors and freezes all running processes. While-m mem
will suspend to RAM and put the system into low-power state to conserve more power, according to rtcwake(8).Explanation
This code will first run the
rtcwake
, suspend the computer until 5.30 a.m., leaving the console open while the computer sleeps, and then play the music usingcvlc
(Console VLC). I'm not sure why thesudo
privilege must be included. I guess that's just the nature of rtcwake. The semicolon;
is used so that the code on the left of the semicolon is run first, and then the second code (to the right of the semicolon) is run after the first code is completed. This is similar to running two commands separately:But since we can't wait until the computer wakes again and play the music by ourselves, we interject these two commands with a semicolon
;
.Required Packages
To use the VLC functionality, you can install it using the command below:
The
cvlc
command will only play the music in the background without actually opening the VLC windows interface. To turn off the 'alarm', you can close the console or press Ctrl+C.