Tuesday, May 7, 2024
 Popular · Latest · Hot · Upcoming
39
rated 0 times [  39] [ 0]  / answers: 1 / hits: 63388  / 2 Years ago, tue, december 21, 2021, 1:57:39

Is there a way to run a script when a computer "wakes up" (from sleeping)? I know it can be done on startup, obviously, but the issue in this case is that the backlight of my laptop seems to reset every time it wakes up from sleep, and I'd ideally like to have a script take care of turning it down to a reasonable level instead of having to type it in manually every time.


More From » scripts

 Answers
4

pm-utils provides a bunch of scripts that run on sleep/resume, you could add your script there, but you'll need to be careful as screwing up will likely break resume. Look in /usr/lib/pm-utils/sleep.d, that's where the scripts are, you can look at the script called 95led as it's quite simple and will be a good model to start with.



95led provides cases for hibernate/suspend and thaw/resume, if you only want resume, you'd write your script like this:



#!/bin/sh

case "$1" in
resume)
echo "hey I just got resumed!"
run_some_command
esac


Your script should probably run last, so make sure it shows up last in the directory, maybe name it 99ZZZ_myscript or something. Again, if you're not sure what you're doing here, I wouldn't mess with it. You may end up breaking suspend/resume. If that happens you can delete the script or fix it, but you'll have to do a hard power-cycle to get your system back up.



There may also be a simpler way, but I know this method will work.


[#33825] Thursday, December 23, 2021, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
rowbris

Total Points: 419
Total Questions: 122
Total Answers: 101

Location: Norway
Member since Mon, May 23, 2022
2 Years ago
;