I have a systemd unit which execute a script that is supposed to play a sound in case a certain event happens i.e. it contains a line

mplayer /home/myusername/Music/audiofile.WAV

This does not happen. The script looks correct, since it works when run on its own.

Why does this happen and how do I fix it?

  • Does the script get executed and no sound is played or is it possible that no sound is played because the script is not executed? – Wieland Dec 22 '15 at 13:39
  • The script is executed, as systemctl status shows. The problem is solved by adding a couple of lines in the systemd unit, which I include in the next answer – Reyx_0 Dec 22 '15 at 15:07
up vote 0 down vote accepted

This happens because the systemd unit is not run by the user as default. In the systemd unit, under the section service, add the following two lines

User=<yourusername>
Environment=DISPLAY=:0

and the unit should work.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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