As you know any terminal emulators have been closed after doing their jobs.
But if you want to gnome-terminal not to be closed using this script in /etc/pm/sleep.d
path (this script cause to keep terminal opened until you hit enter) :
sudo nano /etc/pm/sleep.d/myscript
Then paste these content to you script :
#!/bin/bash
case $1 in
thaw|resume) gnome-terminal --command 'bash -c "compiz --replace &; read line"'
;;
esac
Then make it executble by this command:
sudo chmod a+x /etc/pm/sleep.d/myscript
I hope that's work for you.
UPDATE:
Thanks for sharing. I was curious why my systemd based script did not work. My command works on an opened gnome-terminal but somehow won't work with systemd-suspend.service solution. Could you try on your system to see it has any effect? You can replace the compriz command with command "sleep 20" to try. Appreciate your feedback
The suspend way is different on many machines some of them use sudo pm-suspend
and some of them use systemctl suspend
command.
We can use systemd based script if we use systemctl suspend
for OS sleep (not to use sudo pm-suspend
. but in some systems, when you click on suspend boton, the operating system use pm-suspend
command).
But the systemd based scripts and powermanagement based scripts have a little difference with each other:
In systemd based script we can't run GUI applications because in that condition there is no X server for it to connect to.
So you can't use gnome-terminal
in such commands like gnome-terminal --command 'compiz --replace &'
. if you want to show gnome-terminal you must use powermanagement based scripts.
But in your case it's enough to use this script (without gnome-terminal):
#!/bin/sh
if [ $1 = post ] ; then
compiz --replace &
fi
And you can test your script by replacing something like touch /home/YOURUSERNAME/Desktop/test.txt
instead of compiz --replace &
:
#!/bin/sh
if [ $1 = post ] ; then
touch /home/YOURUSERNAME/Desktop/test.txt
fi
(Be aware that because in systemd based scripts the root user run commands so do not use ~/Desktop
instead of /home/YOURUSERNAME/Desktop
because the the root user's ~ is not your home directory !)
compiz --replace&
solves my display issues only when executed from a terminal. Hence, I usedgnome-terminal
to issue the command. You might want to re-check. Noted on the diff between systemd and powermanagement. ;) – Sun Bear Apr 08 '17 at 06:11