0

Once the system is inactive, in 10 minutes it goes in a blank screen (but not in sleep!) and that's precisely the moment I'd like to execute a long-running script in a terminal while I go for a coffee or take a break. When I come back and "wake up" the system (although technically it's not "sleeping"), I can manually stop the running program that has been executed at the screen off.

Example of such a command:

/usr/bin/screen -S screen-off -dm my-command

There is a bunch of similar questions (Execute a script upon logout/reboot/shutdown in Ubuntu) but they address services that are executed upon the sleep and wake up and this does not suit my needs.

dizcza
  • 115
  • 8

1 Answers1

1

Using dbus-monitor you can watch for the screensaver signal like this:

dbus-monitor --session "type='signal',interface='org.gnome.ScreenSaver'" |
  while read x; do
    case "$x" in 
      *"boolean true"*) echo "Start my script";;
      *"boolean false"*) echo "Cancel my script";;  
    esac
  done

Replace the echo statements with whatever you need, and you should be good to go.

matigo
  • 24,752
  • 7
  • 50
  • 79