2

How do I automatically start an application on resume after suspend or hibernate?

The reason I want to do this is because I've created a script to set xinput value on startup application, but after suspend or hibernate the value in xinput back to default.

Nur
  • 4,081

1 Answers1

1

Place the custom shell script in /etc/pm/sleep.d. Here's an example script which restarts autokey-gtk:

#!/bin/bash

case "$1" in
    hibernate|suspend)
        ;;
    thaw|resume)
        pkill autokey-gtk
        nohup autokey-gtk 2>&1 > /dev/null &
        ;;
    *)
        ;;
esac

The script name should start with 99, or something like that. For example: 99_my_resume.bash.

And don't forget to make it executable:

chmod +x 99_my_resume.bash
Adobe
  • 3,891
  • This doesn't work, I can't suspend or hibernate with 99*.bash file in sleep.d – Nur Jul 09 '13 at 22:19
  • Did You run it as /etc/pm/sleep.d/99_my_resume.bash suspend to suspend? Also You didn't ask to suspend, You asked to run a program on resume. So did You try it? – Adobe Jul 10 '13 at 07:55
  • No, that 99 file is my script, which I expect to run after resuming from suspend. My machine is able to suspend before I put that file in sleep.d, but if the 99 file in sleep.d, I cant suspend, I dont know if it works or not after suspend because I cant suspend at all with the file in sleep.d – Nur Jul 10 '13 at 11:35
  • You did chmod, right? I would try what the command line complains when it fails to suspend, if I were You. Here's a link to suspend from command line. – Adobe Jul 10 '13 at 13:54
  • You see I've used the way for some time myself. A year ago or something like that. It should be working. – Adobe Jul 10 '13 at 13:55
  • Yes i've made it executable, looks like my problem cant be solved and I have to run my script manually when resuming from suspend, not a big deal though, just need a double click and click run. anyway, thanks for answering. – Nur Jul 10 '13 at 20:56