You are not logged in.

#1 2020-11-10 09:10:01

dcaspar
Member
Registered: 2020-08-12
Posts: 51

run script when computer wakes from sleep

i have a simple dmenu to-do list script on my system.
i would like to be able to run the script when my system wakes from sleep, reminding me of my tasks.

i have tried creating an executable script in /usr/lib/systemd/system-sleep/

#!/bin/sh
case $1/$2 in
  pre/*)
    ;;
  post/*)
    /home/usr/privacy313/scripts/todo
    ;;
esac

but it doesn't appear to do anything.
any help would be greatly appreciated/

Offline

#2 2020-11-10 12:40:47

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 77,696

Re: run script when computer wakes from sleep

https://gist.github.com/AladW/de1c5676d93d05a5a0e1

You can also hardcode at least the DISPLAY and user variable, but the script is run as root w/o knowledge of the $DISPLAY.

Online

#3 2020-11-10 15:31:29

dcaspar
Member
Registered: 2020-08-12
Posts: 51

Re: run script when computer wakes from sleep

does this go in /usr/lib/systemd/system-sleep/ and if so where should i define the todo script to be loaded?

Offline

#4 2020-11-10 15:41:13

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 77,696

Re: run script when computer wakes from sleep

What?
The point is that you need to explicitly export the DISPLAY variable to dmenu and also run it as the user that runs the X11 session (your regular UID)
Whether you do that in the sleep hook or /home/usr/privacy313/scripts/todo or somewhere else entirely doesn't matter - but I assume you want to do it in the sleep hook unless you maybe also want to use a systed timer or cronjob to trigger the todo script.

nb. that the linked script to import the variables looks for the xinit process on the active terminal. If you do not use xinit, you'll  have to adapt it.

Online

#5 2020-11-10 16:15:27

dcaspar
Member
Registered: 2020-08-12
Posts: 51

Re: run script when computer wakes from sleep

thanks.
so i see this should go inside the sleep hook in my case.

i first tried directly defining display and UID in the sleep hook by adding

DISPLAY=:0
UID=1000

no luck there.
so i tried to add the script you linked in the sleep hook prior to the case statement. i am using xinit, so there shouldn't be a complication there.
also no luck however.
i guess i'm still missing something..

Offline

#6 2020-11-10 18:27:06

seth
Member
From: Won't reply 2 private help req
Registered: 2012-09-03
Posts: 77,696

Re: run script when computer wakes from sleep

This is one of the rare occasions where sudo is going to fix it - in particular "sudo -u ..."
Edit: also you probably did no "export" the variables?

Last edited by seth (2020-11-10 18:27:49)

Online

Board footer

Powered by FluxBB