2

I have a script that sets up my mouse preferences and it’s placed in Startup applications. It runs on startup, but when the lid is closed or the computer manually put in suspend (same thing really), the settings get removed. I have it so Ubuntu requires my password on return from suspend, but this login doesn’t seem to be the same as a regular login, as it doesn’t execute .profile or .bashrc.

I tried placing my script in /lib/systemd/system-sleep/ but this executes before entering my password and it doesn’t seem that xinput commands work at that point in the wake up cycle because the changes don’t take effect.

So I’m either looking for a way to make every suspend also execute a lock or log off cycle (as locking manually executes .profile) or find a way to execute a script specifically on the password entry on resume from suspend.

  • Can you give example of his you are using xinput command? – WinEunuuchs2Unix May 18 '18 at 21:20
  • Yeah, one of the lines in the script is "xinput --set-prop 12 291 -1". This sets the acceleration (option 291) of the trackpad (input 12) to -1 (so no acceleration). I had a script in /lib/systemd/system-sleep/ that would print text to a file on wakeup. It would work fine, but as soon as I added the xinput commands, the script would crash and not finish (I had two echo "text" >> test.txt commands sandwiching the xinput commands. The second wouldn't complete when the xinput commnds were added to the script). – Sam Thibodeau May 22 '18 at 18:17
  • You should post the script into your question. Then people answering can use your script setup rather than their own. For example mine would be with WiFi or Ethernet kernel modules reloading after sleep. – WinEunuuchs2Unix May 22 '18 at 18:36
0

Scripts in /etc/systemd/system-sleep/ are running as root who isn't signed into X11 windowing system. So it needs to inherit profile from logged in user.

From eyesome screen brightness and gamma app this works for me:

#!/bin/bash

export DISPLAY=:0       # For xrandr commands to work.
SpamLength=2            # How long spam lasts (how many seconds to sleep)

WaitForSignOn () {

    # eyesome daemon is loaded during boot. The user name is required
    # for xrandr external monitor brightness and gamma control. We must
    # wait until user signs on to get .Xauthority file settings.

    TotalWait=0

    # Wait for user to sign on then get Xserver access for xrandr calls
    UserName=""
    while [[ $UserName == "" ]]; do

        sleep "$SpamLength"
        TotalWait=$(( TotalWait + SpamLength ))

        # Find UserName currently logged in.
        UserName="$(who -u | grep -F '(:0)' | head -n 1 | awk '{print $1}')"
    done

    logger "Waited $TotalWait seconds for $UserName to login."

    xhost local:root
    export XAUTHORITY="/home/$UserName/.Xauthority"

} # WaitForSignOn

You can copy the above code into the top of your script and then insert one line in front of your existing code:

WaitForSignOn

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.