Thursday, February 22, 2024
 Popular · Latest · Hot · Upcoming
18
rated 0 times [  18] [ 0]  / answers: 1 / hits: 14105  / 2 Years ago, mon, april 25, 2022, 11:56:29

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?


More From » 12.04

 Answers
7

You are right. You have to write a script and save it to /lib/systemd/system-sleep/ (since 2015 systemd take care of that, before was /etc/pm/sleep.d/). The difference between suspending and resuming is given as a parameter 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.


[#32871] Tuesday, April 26, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rtbrbab

Total Points: 461
Total Questions: 126
Total Answers: 117

Location: Saudi Arabia
Member since Fri, Jul 1, 2022
2 Years ago
rtbrbab questions
Fri, May 5, 23, 14:22, 10 Months ago
Tue, Nov 16, 21, 14:41, 2 Years ago
Thu, Mar 23, 23, 20:47, 1 Year ago
Sat, Jun 18, 22, 21:36, 2 Years ago
;