I've got a script that is executed in order to have suspending/resuming working in my laptop. Then I have another series of xinput
,xkbset
and xmodmap
commands that are executed when I initiate a session to have two-finger scrolling and keyboard shortcuts set up. When I resume from suspend, two-finger scrolling and my keyboard shortcuts won't work. I need to manually execute the commands in the second file again. How can I add those to the suspend/resume script to have this done automatically? See below:
suspend/resume script
/etc/pm/sleep.d/20_custom-ehci_hcd
#!/bin/sh
#inspired by http://art.ubuntuforums.org/showpost.php?p=9744970&postcount=19
#...and http://thecodecentral.com/2011/01/18/fix-ubuntu-10-10-suspendhibernate-not-working-bug
# tidied by tqzzaa :)
VERSION=1.1
DEV_LIST=/tmp/usb-dev-list
DRIVERS_DIR=/sys/bus/pci/drivers
DRIVERS="ehci xhci" # ehci_hcd, xhci_hcd
HEX="[[:xdigit:]]"
MAX_BIND_ATTEMPTS=2
BIND_WAIT=0.1
unbindDev() {
echo -n > $DEV_LIST 2>/dev/null
for driver in $DRIVERS; do
DDIR=$DRIVERS_DIR/${driver}_hcd
for dev in `ls $DDIR 2>/dev/null | egrep "^$HEX+:$HEX+:$HEX"`; do
echo -n "$dev" > $DDIR/unbind
echo "$driver $dev" >> $DEV_LIST
done
done
}
bindDev() {
if [ -s $DEV_LIST ]; then
while read driver dev; do
DDIR=$DRIVERS_DIR/${driver}_hcd
while [ $((MAX_BIND_ATTEMPTS)) -gt 0 ]; do
echo -n "$dev" > $DDIR/bind
if [ ! -L "$DDIR/$dev" ]; then
sleep $BIND_WAIT
else
break
fi
MAX_BIND_ATTEMPTS=$((MAX_BIND_ATTEMPTS-1))
done
done < $DEV_LIST
fi
rm $DEV_LIST 2>/dev/null
}
case "$1" in
hibernate|suspend) unbindDev;;
resume|thaw) bindDev;;
esac
touchpad two-finger scrolling and keyboard shortcuts script
xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Two-Finger Scrolling" 8 1
xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Synaptics Two-Finger Scrolling" 8 1 1
xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Synaptics Two-Finger Pressure" 32 10
xinput set-int-prop "SynPS/2 Synaptics TouchPad" "Synaptics Two-Finger Width" 32 8
setxkbmap -layout gb
xkbset m
xkbset exp =m
xmodmap -e "keycode 135 = Pointer_Button2"
You can place your scripts in the
/etc/pm/sleep.d
directory to have them run after suspend. You will need to add a conditional to make your script run only during resume and not during the suspend process as well. For example, your touchpad script would look like:Be sure your script is marked globally executable and change $USER to the corresponding username.
You can find more detailed information in the pm-suspend manpage (
man pm-suspend
) or by looking at the documentation in/usr/share/doc/pm-utils
(particularly/usr/share/doc/pm-utils/HOWTO.hooks.gz
).On Ubuntu 16.04 I had to create service this way:
create file
put inside
enable service
(optional) if not working after resume from suspend > check for errors with
Open this file:
Contents:
Your command will execute with admin privileges.
Here is the version I use to restart my VPN daemon after resume:
This file is put in:
This works fine in Ubuntu 20.4. The
pre
part is executed before putting the computer to sleep (suspend
) and thepost
part is executed when it is resumed, as that can be verified by looking at the/tmp/nordvpn/suspend.txt
file.Side note (irrelevant to the subject but worth noting): Regarding the task in this example, it might seem illogical to restart a daemon before putting the computer to sleep, but it's the (only?) way it works.