The usual advice about this issue is to disable powersaving when watching a flash video and then reenable it when done. I have always found this to be a bit of a pain.
To use this method, do the following:
-
Install package “yad” (similar to “kdialog” but with a few more options) from the Packman repository.
-
Copy and paste the following into a text file named “sleep.sh” and save it into your ~/bin directory. Make it executable:
#!/bin/bash
#get current idle load
IDLE=$(top -b -n 2 | grep Cpu)
#check for parameter; if none, set LIMIT to default of 98.0
if -z "$1" ]; then
LIMIT=98.0
else
LIMIT=$1
fi
#multiply IDLE and LIMIT by 10 and convert both to integers
IDLE=${IDLE:114:4}
IDLE=$(echo "$IDLE*10" | bc)
IDLE=${IDLE%%.*}
LIMIT=$(echo "$LIMIT*10" | bc)
LIMIT=${LIMIT%%.*}
#compare IDLE and LIMIT
if "$IDLE" -ge "$LIMIT" ]; then
#play warning sound, start countdown timer
play -q /usr/share/sounds/KDE-Sys-Warning.ogg &
yad --title Warning!\
--button=gtk-cancel\
--text="System suspending in 60 sec!
"\
--timeout 55\
--timeout-indicator bottom\
--image=/usr/share/icons/default.kde4/64x64/status/dialog-warning.png\
--auto-close &
else
#simulate keypress
dbus-send --print-reply\
--type=method_call\
--dest=org.freedesktop.ScreenSaver /ScreenSaver org.freedesktop.ScreenSaver.SimulateUserActivity
fi
exit
- Go to System Settings–> Power Management. Check the box next to “Run Script”, and in the box “Script” point it to the file “~/bin/sleep.sh”. In the dropdown box below this (“Run script”) select “After”. Set the timer to one minute before the earliest power management option you have selected, e.g., if you have “Suspend Session” set to 10 minutes, set your script to run after 9 minutes.
What it does: The principle is that if the system idle load is greater than or equal to a certain percentage, the script will conclude that nothing is going on and will allow the system to go into power saving mode. If the idle load is less than this percentage, it will conclude that you are doing something that is using processor resources, such as watching a flash video, talking on Skype, etc., and will then simulate a keypress to restart the power management timer.
First the script executes “top” for two iterations, selects the lines containing the string “Cpu” and stores the output as “IDLE”. It does two iterations of “top” because the first one seems always to show the idle load to be lower than it really is, possibly due to the overhead of loading “top” to start with. It then checks to see if a parameter has been passed to the script. If there is one it will set the variable “LIMIT” to this value, otherwise it will set it to the default value of 98.0%. You might find that a different value works better for your system. If you do, pass it to the script in the form “xx.x”. It then finds the 114th character in the string “IDLE”, which is the location of the second value of the system idle percentage, and resets “IDLE” to the four characters starting there, giving the system idle percentage in “xx.x” form. It then multiplies this value along with “LIMIT” by 10 and then converts both values to integers.
It then compares the two values. If the system idle percentage is greater than or equal to the defined limit, it will sound a warning and display a dialog box with a countdown timer. Clicking on “Cancel” (or actually any mouse or keyboard activity) will reset the power management timer and the system will remain active. If, however, no activity occurs, the countdown timer will expire and the system will then go into power saving mode.
If, on the other hand, the system idle percentage is lower than the defined value, a keypress is simulated and the system remains active.
This works for KDE. It might work with Gnome but I don’t know if this has any option for running a script after a certain time. It could probably be run with a “cron” script if necessary but I haven’t looked into this.