#!/bin/bash #################################### # nosleep.bash v2.0 # Create by Sylvain GARGASSON # Under GPL v3 # Stop ScreenSaver and power-manager # using like: nosleep.bash vlc #################################### ### Variable you can adapte ### screensaver=/apps/gnome-screensaver powermanager=/apps/gnome-power-manager/timeout gconf_get_value(){ gconftool-2 -g $*;} gconf_get_type(){ gconftool-2 -T $*;} gconf_set(){ gconftool-2 -s -t $*;} line=("$screensaver/idle_activation_enabled" "$powermanager/sleep_computer_ac" "$powermanager/sleep_computer_battery" "$powermanager/sleep_computer_ups" "$powermanager/sleep_display_ac" "$powermanager/sleep_display_battery" "$powermanager/sleep_display_ups") ### DON'T TOUCH AFTER HERE ### get_values(){ for ((i ; i< ${#line[@]}; i++)) do value[$i]=$(gconf_get_value ${line[$i]}) type[$i]=$(gconf_get_type ${line[$i]}) echo "gconftool-2 -s -t ${type[$i]} ${line[$i]} ${value[$i]}" >> ~/.nosleep.save done i=0 } set_values(){ for ((i ; i< ${#line[@]}; i++)) do if [ "$1" = "nosleep" ] then gconf_set ${type[$i]} ${line[$i]} 0} else gconf_set ${type[$i]} ${line[$i]} ${value[$i]} fi done i=0 } show_values(){ for ((i ; i< ${#line[@]}; i++)) do echo ${line[$i]}=$(gconf_get_value ${line[$i]}) done i=0 } ### NOSLEEP NOW REALLY START ### ## RESTORE YOUR VALUES AND PRINT IT AFTER CRASH IF NEED ## if [ -e ~/.nosleep.save ] then chmod +x ~/.nosleep.save bash ~/.nosleep.save rm -f ~/.nosleep.save echo -e "\nAFTER CRASH YOUR SCREENSAVER AND POWER-MANAGER HAVE BEEN RESET TO YOUR PERSONAL VALUES:\n" show_values fi ## GET VALUES, SAVE IT FOR CRASH PREVENT AND PRINT IT ## get_values echo -e "\nThe nosleep script have start. Your Actual values are:\n" show_values ## SET NO SPLEEPING VALUES AND PRINT IT## set_values nosleep echo -e "\nThe nosleep script have disable screensaver and power-manager. Your Actual values are:\n" show_values ## CHANGE “Internal Field Separator” FOR NOT HAVING SPACE TROUBLE ## OLD_IFS=$IFS IFS=$'\n' ### LAUNCH YOUR APP ### "$@" #And not "$*" for Mr khatar ### END OF YOUR APP ### ## RESTORE “Internal Field Separator” ## IFS=$OLD_IFS ## RESTORE YOUR VALUES, DELETE THE CRASH PREVENT FILE AND PRINT IT ## set_values rm -f ~/.nosleep.save echo -e "\nThe nosleep script have rollback your values. Your Actual values are:\n" show_values echo -e "\n" exit 0