I like to have my computer sleep to RAM under certain conditions, and of course being the geek I am, I want full control over those.
Enter this small script which will put your computer to sleep if idle since > N minutes (using xprintidle) AND if some applications are not running (You would not want your computer to go to sleep while you use it to listen to music, are downloading something or are doing a backup)
Of course it doesn't cover all cases (What to do about the browser ?) but I believe it's still a pretty good basis
check vlc &&
check mpv &&
check transmission &&
check virt-manager &&
check xfsdump &&
check emerge &&
sleep $check_interval # After sleep, don't check before N minutes
if [ $? != 0 ]
printf "not using $1\n"
printf "using $1, skipping sleep\n"
# Base variables
# Handle options
while test $# -gt 0; do
case "$1" in
while [ 1 ]
if [ $current_idle -gt $max_idle ] # 10 mins
printf "Computer has been idle for 10 minute\n"
sleep $check_interval # Check every 30 seconds