Monday, May 6, 2024
 Popular · Latest · Hot · Upcoming
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 10995  / 1 Year ago, sun, february 12, 2023, 5:16:35

In Ubuntu 12.04 LTS, I would like to run scripts after resuming from suspend, and after unlocking my desktop. These need to run as my user, and with access to my $DISPLAY.



In particular, I would like to




  • restart nm-applet to work around bug 985028

  • show a custom notification using notify-send

  • possibly other stuff when I get these working



When I resume, scripts in /etc/pm/sleep.d/ are run, but they run as root, without knowledge of my screen and username. It might work if I hard-code my username and export the default DISPLAY :0 in these scripts, but that feels like a very ugly hack.



Scripts in ~/.config/autostart/xyz.desktop run after login, but they don't run after merely unlocking the screen after resume.



Is there a way to run scripts after unlocking the screen after a resume?


More From » 12.04

 Answers
3

One solution is a script which runs when logging into the desktop, and which catches dbus messages. After resume from suspend the screen is locked, and after entering the password, there is an Unlock event on dbus.



(Thanks to Kim SJ for putting me on the right track. I have no ScreenSaver signals, but found another interface to use).



In ~/.config/autostart/, I have a .desktop file which starts a bash script:



$ cat ~/.config/autostart/mymonitor.desktop
[Desktop Entry]
Categories=System;Monitor;
Comment=Monitor dbus for unlock signals
Exec=/usr/local/bin/unlock_monitor
Name=unlock_monitor
Type=Application


The unlock_monitor monitor script reads dbus messages from com.canonical.Unity.Session and does stuff on Unlocked signals:



#!/bin/bash

dbus-monitor --session "type=signal,interface=com.canonical.Unity.Session" --profile
| while read dbusmsg; do
if [[ "$dbusmsg" =~ Unlocked$ || "$dbusmsg" =~ NameAcquired$ ]] ; then
sleep 5
notify-send "$(basename $0)" "Unlocked or freshly logged in..."
# ...
fi
done


When logging in, there is no "Unlocked" signal, but there is a "NameAcquired" signal when dbus-monitor starts.


[#34809] Sunday, February 12, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
utilitere

Total Points: 394
Total Questions: 110
Total Answers: 114

Location: Solomon Islands
Member since Wed, Mar 29, 2023
1 Year ago
;