Question: How to assign a script to run when selecting the suspend option on the power menu?

Context:
I have a Sony VAIO laptop with an AMD Radeon graphics card. I would like to be able to disable/enable the discrete graphics card. I have no problem in doing this but it causes problems when suspending & resuming from suspend.

When the session is resumed from suspend (with the discrete DPU disabled), the fan will spin up uncontrollably, what I would like to do is edit the suspend script or assign a new script to the suspend option on the power menu. This is so I can re-enable the GPU before suspending. Power Menu

EDIT: After some research I think it has something to do with the files in /etc/pm/sleep.d/?

If I put a custom script in there would it be run when suspending and resuming from suspend?

How do I differentiate in the script between suspending/resuming?

up vote 15 down vote accepted

You are right. You have to write a script and save it to /etc/pm/sleep.d/. The difference between suspending and resuming is given as a paramater to the script:

#!/bin/bash

case "$1" in
    suspend)
        # executed on suspend
        ;;
    resume) 
        # executed on resume
        ;;
    *)
        ;;
esac

If you also want to do it for hibernate, the arguments would be hibernate and thaw.

  • I'd seen this in other scripts and was wondering on the specific requirements for such a script. Thank you :) – danielcooperxyz Feb 25 '13 at 13:38
  • Hi, tried this on my Dell 5570 running ubuntu 14.04 to get it to turn my touchpad on, if I'd turned if off before suspending. for some reason, the command tp_id= ()xinput list | grep -i touchpad | awk '{ print $7 }' | sed 's/id=//'() is not returning the id, while this command does work from the command line. Can you see any reason why it wouldn't? For other purposes you script works great. Thanks! – Leo Simon Mar 11 '16 at 0:16
  • Sorry, in that previous comment, I tried to put backticks into the script fragment, but the minimarkdown language defeated me. the ()'s are meant to be replaced by backticks – Leo Simon Mar 11 '16 at 0:27
  • @LeoSimon Hey Leo, the comments are not the right place to discuss such a follow up question. I suggest you ask an entirely new question. This way a lot more people will see it and be able to help you :-) – André Stannek Mar 11 '16 at 8:55
  • 1
    You may need to use /lib/systemd/system-sleep/ instead. – SimonT Oct 20 '17 at 5:17

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.