Execute a script whenever Linux Mint resumes from suspend

2

I'm running Linux Mint. I have a script the gets run whenever I login that remaps my mouse buttons. However, when the computer suspends, the mouse buttons revert to their default mapping.

I'd like to have my script re-run whenever the computer awakes from suspend. How can I do this? Currently I'm just calling the script from the "Startup Applications" control panel.

I already tried putting some copies of my script in subdirectories within /etc/pm, but that didn't work.

EDIT: Actually when my computer comes out of suspend, sometimes the mouse mapping hasn't been reset. But when I turn the monitors off, then back on (using their power buttons) the mouse mapping has always been reset. How can I prevent this? (Or where can I put a script so it will run when the monitors turn back on?)

Jeff

Posted 2013-08-10T19:39:40.860

Reputation: 271

Answers

3

It is possible that the reason why your script "doesn't work" is due to several reasons:

  • The script is not executable. It should be executable (run chmod +x on it).
  • The script is running as root when the system reboots (I think). To run it as your user, try something like:
#!/bin/bash

case "$1" in
hibernate|suspend)
sudo -u USERNAME env DISPLAY=:0 zenity --info --text "do stuff on suspend" ;;
thaw|resume)
sudo -u USERNAME env DISPLAY=:0 zenity --info --text "do stuff on resume"
;;
esac

(stolen shamelessly from AskUbuntu).

Obviously you can replace the zenity call with the action you want to take when resuming from suspend. USERNAME should be the user you're normally logged in as (if this changes a lot, that could get complicated).

ChatBot John Cavil

Posted 2013-08-10T19:39:40.860

Reputation: 156

It's executable. I added sudo -u but that didn't fix it, though clearly I needed to add that---just forget to include that before. Thanks for pointing that out. – Jeff – 2013-08-11T21:43:17.350

+1 for showing thaw|resume - the template script I was looking for only had thaw, and I needed resume to get out of a sleep, rather then suspend state. – davidgo – 2013-09-01T08:36:29.933