Running an X application from a shell script via systemd timer Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Running an X application from a shell script via systemd timer without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I’m trying to create a systemd (user) timer that opens certain tabs every day at 9PM with xdg-open. Here are the files:



ExecStart=/bin/bash /home/me/


Description=Test Timer

OnCalendar=*-*-* 21:00:00





for i in "${websites[@]}"
    # works with /usr/bin/firefox
    /usr/bin/xdg-open "$i"

This doesn’t open anything.

When I replace xdg-open with firefox in the above file, the tabs get opened. However, when I execute xdg-open "" in a terminal it opens a tab in Firefox.

systemctl --user start test.service 
systemctl --user status test.service 


‚óŹ test.service - Test
   Loaded: loaded (/home/me/.config/systemd/user/test.service; static; vendor preset: enabled)
   Active: inactive (dead)

Jun 29 15:06:59 me-PC systemd[1513]: Started Test.

How can I make this timer work with xdg-open?


Often differences between running a script manually and running it via systemd are due differences in the environment. Before the xdg-open call, add the command env on it’s own line, which dumps the environment.

Now run the test manually and via systemd. Look for other variables besides DISPLAY that could be causing the difference. By continuing to add environment variables into the systemd script, you should be able to find the ones systemd needs to make this work.

Your bash code in your test looks fine, but here’s a revision that’s a bit more idiomatic if you are interested. bash naturally splits on space and URLs don’t contain space, so this alternate code works. I’ve also replaced do/done with braces:


for i in $websites; {
    # works with /usr/bin/firefox
  /usr/bin/xdg-open "$i"
We are here to answer your question about Running an X application from a shell script via systemd timer - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji