I don't know if there is a way to run things after entering your password as you request and I doubt there will be since that is handled by the desktop environment (probably the screensaver daemon). However, it should work perfectly well if you add the right scripts to /etc/pm/sleep.d
. Since you have not shown the scripts you've tried, my guess is that you simply did not write the script correctly. The following works fine on my system:
Create a file called /etc/pm/sleep.d/20_resume
with the following contents:
#!/bin/sh
case "$1" in
thaw|resume)
/home/terdon/scripts/onoff.sh
;;
esac
exit $?
Make sure to adapt the path above (/home/terdon/scripts/onoff.sh
) to the actual path of the script shown in step 3.
Give the file the right permissions (rwxr-xr-x
)
sudo chmod 755 /etc/pm/sleep.d/20_resume
Write a script that turns off the touchpad if a mouse is connected and on if there is no connected mouse:
#!/bin/sh
## Get the xinput ID of the touchpad
TID=$(xinput list | grep -iPo 'touchpad.*id=\K\d+')
## Check if a mouse is connected and act accordingly
xinput list | grep -iq mouse && xinput disable "$TID" || xinput enable "$TID"
Now save the script above using the path and name from step 1 (in this example, /home/terdon/scripts/onoff.sh
), make it executable (chmod +x /home/terdon/scripts/onoff.sh
) and you should be set.
If this is what you've already tried, please edit your question and show us the scripts you've used.
The other approach I can think of is to use the procedure outlined in my answer to your other question. I don't understand what you have against loops, they are a perfectly valid and indeed invaluable programming construct. The only issue I can think of is that running an infinite loop can tax your CPU but that should not be a problem if your script uses sleep
to wait for a second or two between each loop run. Since my suggestion does just that, you can simply use that if the above fails you.
You are using the default nouveau driver, for your nvidia graphics card. This is a reverse engineered driver and is known to cause trouble with power management.
From what I can tell from my experience suspend with nouveau is gambling, depends very much on the kernel version, graphics card etc.
The first thing I would try if I were you is installing the official nvidia driver: Note, though, it is proprietary, but I would try to see if it resolves your problem, because then we know pretty much for sure nouveau is the component to blame. (Looking at all the errors on your screen I am pretty sure though nouveau is the trouble maker.)
If you have concern because the proprietary driver is closed source, you can set up a second ubuntu install on an external hdd/usb and try it there.
To try the proprietary nvidia driver do the following:
sudo apt-get install nvidia-current-updates
and reboot your machine after the process finished.
Please report back if that changes something for you.
If not, my second try would be disconnecting all external hardware (usb devices like scanners, printers etc.), to make sure nothing external triggers a wakeup.
EDIT: Please also paste the output of
lspci
since the error message on your screen says "Device 0000:01:00.0 failed to suspend" and that command helps us to find what device exactly that is, but I suppose your graphics card.
Added by questioner:
For all who have similar Problem with a Nvidia Card in a laptop, If you have further trouble (eg. if your OpenGL Version is still low, or your laptop needs a lot of energy), check if your card uses OPTIMUS technology. This means that you have an additional graphics card, which is used for not graphical expensive Applications. In contrast this second card is optimized for low energy usage. You can search on the in the optimus scetion on the Nvidia Site for your card. If found your card there install also bumblebee
and bumblebee-nvidia
. After that, to run a Application with your powerful graphics card you have to run your Application via
$ optirun <path to app>
Best Answer
To automate the call to your script on wakeup, you can add it under
/lib/systemd/system-sleep
instead of/usr/lib/pm-utils/sleep.d
Here is what I've done:
sudo touch /lib/systemd/system-sleep/touchpadwakeup
sudo chmod +x /lib/systemd/system-sleep/touchpadwakeup
It works fine but I hope we'll have a cleaner solution (e.g, a patch) in the near future.