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.

21
  • You can try this: askubuntu.com/questions/92218/… with the command gnome-shell --replace.
    – pomsky
    Jul 4, 2018 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, 2018 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, 2018 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, 2018 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, 2018 at 19:46

2 Answers 2

2

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.

1
  • 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, 2018 at 4:27
0

I know this reply is a bit late, but I will post my method, maybe it will be useful to someone :-). !!! Only works with Xorg!!!.

The solution I found (a trick) is to create a script in /lib/systemd/system-sleep that stores a value ("1") in a file every time it wakes up from sleep, and I have another script that is always running that checks the contents of that file and when it is equal to "1" it runs the shell restart code and then changes the contents of the file to "0". The code to restart the shell is also a "trick" as I haven't found a command to do this, where I have to use xdotool to simulate keypress and mouse click.

Scripts:

  • /lib/systemd/system-sleep/resume_status
#!/bin/sh

if [ "${1}" == "post" ]; then
  sleep 5 
  echo "1" > PATH-TO-FILE/FILE
fi


sleep 5 is used to wait the system to enter graphical environment

  • a user script to check the resume from sleep (placed somewhere in your HOME) :
#!/bin/bash

while true; do
    check=$(sed '1q;d'  PATH-TO-FILE/FILE)
    if [[ "$check" == "1" ]]; then
        xdotool key alt+F2
        sleep 1
        xdotool click 1
        xdotool type 'r'
        xdotool key Return
        echo "0" > PATH-TO-FILE/FILE
    fi
    sleep 5
done

Change PATH-TO-FILE/FILE to match your case and make sure xdotool is installed.

I have been using this method for a while now and it is working fine.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .