Score:1

Ubuntu 22.04 jammy run script on resume

re flag

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.

Score:0
jp flag

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:

fossilised9uhdj avatar
re flag
This worked exactly, thanks a bunch!
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.