I'm trying to run a bunch of scripts/commands every day.
For this purpose I've configured a user-space anacron as explained here. Anacron is started hourly by cron:
contents of /var/spool/cron/rawing
:
@hourly /usr/sbin/anacron -s -t ${HOME}/.anacron/etc/anacrontab -S ${HOME}/.anacron/spool
This works fine. However, I haven't managed to run any graphical applications from my anacrontab. I've tried:
@daily 0 gui_test_env env SCREEN=:0 zenity --info
@daily 0 gui_test_screen SCREEN=:0 zenity --info
Both of these fail with the error message
Unable to init server: Could not connect: Connection refused
(zenity:6034): Gtk-WARNING **: cannot open display:
Also
@daily 0 notify_test SCREEN=:0.0 && notify-send "foobar"
didn't produce an error message, but didn't display a notification either. On the other hand, a python script that displays desktop notifications failed with the message
Unable to init server: Could not connect: Connection refused
Traceback (most recent call last):
File "/home/rawing/Desktop/folder/python/misc/confirm_run.py", line 36, in <module>
n.show()
GLib.Error: g-spawn-exit-error-quark: Error spawning command line 'dbus-launch --autolaunch=db6d4465f8584b8faa8abfb09b242b95 --binary-syntax --close-stderr': Child process exited with code 1 (1)
In case it matters, the python code looks like this (shortened):
from gi.repository import Notify
Notify.init('test')
n= Notify.Notification.new('title', 'question', "dialog-question")
n.set_urgency(Notify.Urgency.NORMAL)
n.show()
Adding xhost local:rawing > /dev/null
to my ~/.bashrc
as suggested here didn't help either.
Update: I've managed to run GUI applications using DISPLAY=:0 XAUTHORITY=/home/rawing/.Xauthority some_gui_app
. Desktop notifications still don't work though. The error is:
Traceback (most recent call last):
File "/home/rawing/Desktop/folder/python/misc/confirm_run.py", line 36, in <module>
n.show()
GLib.Error: g-dbus-error-quark: GDBus.Error:org.freedesktop.DBus.Error.ServiceUnknown: The name org.freedesktop.Notifications was not provided by any .service files (2)
P.S.: Suggestions on how to make this work without anacron are also welcome. I thought anacron would make this easy... turns out I was too optimistic.
org.freedesktop.Notifications was not provided by any .service files
I have seen reports of similar error messages (for example, here on Arch and here on Ubuntu) for which the problem was resolved by installing a notification-daemon. Have you tried that?notification-daemon
reverted the error toGLib.Error: g-spawn-exit-error-quark: Error spawning command line 'dbus-launch --autolaunch=2a4dc02c073e450399e9f344111fbbbb --binary-syntax --close-stderr': Child process exited with code 1 (1)
.(GLib.Error: g-spawn-exit-error-quark: Error spawning command line 'dbus-launch --autolaunch=
</snip> -- did you figure anything out?