3

Since I did not receive any answer to this question and I have to manually restart gnome-shell each time the PC comes back from suspend to correct the distorted colors, I would like to know how to automatically restart Gnome Shell after suspend instead of doing Alt + F2 - r.

Installed Gnome extensions: Dash to Panel and Arc Menu. This is not a duplicate of a previous question. This specifically about automatically restarting Gnome Shell after coming out from suspend. Questions are totally different.

Edit: following the suggestions on comments:

a. Created a file on /etc/systemd/system called restart-gnome-shell.service and add the following:

[Unit] 
Description=Restart Gnome-Shell
Before=sleep.target
StopWhenUnneeded=yes

[Service] 
Type=oneshot 
RemainAfterExit=yes 
ExecStop=-/path/to/script.sh

[Install] 
WantedBy=sleep.target

The script.sh contents are:

#! /bin/bash
gnome-shell --replace

The script has execution permissions and I enabled and started the service which was recognized by systemctl. This did not work.

This is the status after waking up from suspend:

● restart-gnome-shell.service - Restart Gnome-Shell
   Loaded: loaded (/etc/systemd/system/restart-gnome-shell.service; disabled; vendor preset: enabled)
   Active: inactive (dead)

jul 08 12:51:07 Enrique-PC systemd[1]: Started Restart Gnome-Shell.
jul 08 15:53:08 Enrique-PC systemd[1]: restart-gnome-shell.service: Unit not needed anymore. Stopping.
jul 08 15:53:08 Enrique-PC systemd[1]: Stopping Restart Gnome-Shell...
jul 08 15:53:08 Enrique-PC restart-gnome-shell.sh[2119]: Window manager warning: Unsupported session type
jul 08 15:53:08 Enrique-PC systemd[1]: Stopped Restart Gnome-Shell.

b. Created an executable script on /lib/systemd/system-sleep with the following contents:

case "${1}" in
    post)
         gnome-shell --replace
;;
esac

It did not work.

  • You can try this: askubuntu.com/questions/92218/… with the command gnome-shell --replace. – pomsky Jul 4 '18 at 18:20
  • @pomsky thanks, but that command never completes because it says for example that Dropbox client is already registered and never continues. Similar issues with other Ubuntu AppIndicators. – eera5607 Jul 4 '18 at 18:30
  • 1
    Possible duplicate of Color distortion after coming out from suspend on Ubuntu 18.04. Please edit that question with the additional information. – user535733 Jul 4 '18 at 18:34
  • You may have a GNOME extension conflict. Please edit your question to list your set of enabled GNOME extensions shown at extensions.gnome.org/local Report back to @heynnema – heynnema Jul 4 '18 at 18:48
  • 1
    @user535733 This is not a duplicate of a previous question. This is specifically about automatically restarting Gnome Shell after coming out from suspend. Questions are different. – eera5607 Jul 4 '18 at 19:46
0

Change your script from this:

case "${1}" in
    post)
         gnome-shell --replace
;;
esac

To this:

#!/bin/sh

case $1/$2 in
  pre/*)
    echo "Going to $2..."
    # Place your pre suspend commands here, or `exit 0`
    # if no pre suspend action required
    sleep 1
    ;;
  post/*)
    echo "Waking up from $2..."
    # Place your post suspend (resume) commands here, or `exit 0` 
    # if no post suspend action required
    sleep 2
    gnome-shell --replace
    ;;
esac

For sure you are missing #!/bin/sh at the top of your script. Most of the rest of the proposed changes are not be necessary but informative.

  • Thank you. I don't know why it is not working. I used the script that you suggest, copy it to /lib/systemd/system-sleep/ and nothing. – eera5607 Jul 9 '18 at 4:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.