1

When i wake my laptop from sleep the sound doesn't work but pulseaudio --kill && pulseaudio --start fixes it. I want to run this as a wake up script. A good search reveals that the trick is to put a script in /lib/systemd/systemd-sleep/ however, /lib/systemd/systemd-sleep is not a directory - its a file. If you cat the file a lot of is isn't output as text.

Any ideas? basically I need to run the command above on wakeup.

1 Answer 1

0

It's /lib/systemd/system-sleep/ and not "/lib/systemd/systemd-sleep" ... Your scriptfile's contents can look like this:

#!/bin/sh

# "/lib/systemd/system-sleep/" template script

case "${1}" in
  pre)
    # Command(s)/script(s) to execute before system goes to sleep/hibernate
    # nothing
      ;;
  post)
    # Command(s)/script(s) to execute after system wakes up from sleep/hibernate
    /bin/pulseaudio --kill && /bin/pulseaudio --start
    # To run a command as a certain user, use the example below instead ...
    # Changing "username" to the actual desired invoking user name like:
    # /bin/su username -c '/bin/pulseaudio --kill && /bin/pulseaudio --start'
      ;;
esac

Yo need to specify full real path to executables and in case of user services like PulseAudio, you might need to specify the invoking user as well.

You'll obviously need to create the script file, edit and save it first with e.g.:

sudo nano /lib/systemd/system-sleep/script-file-name

Then, make it executable like so:

sudo chmod +x /lib/systemd/system-sleep/script-file-name

You might need to read these related posts as well:

1
  • 1
    This worked exactly, thanks a bunch! May 26 at 6:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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