Ok. You might have to preceed the zenity
command with WAYLAND_DISPLAY=wayland-1
if you’re on Wayland, which you never answered in a previous question above: Cron job doesn't work after update to 24.04 - #6 by steve007morris
I am on wayland; I did reply to the question (“My system behaves the same way”) but that reply did not seem to get attached to the question.
Anyway preceding the zenity command with the wayland setting makes no difference.
Once again, my reply does not seem to get attached to the question
https://bbs.archlinux.org/viewtopic.php?id=260353
Does this help?
https://unix.stackexchange.com/questions/80310/how-to-display-a-zenity-gui-dialog-to-the-user-after-a-root-cron-task-has-comp
Seems if you set the Xauthority file it helps. Not sure if this is using Xorg
One of the things that puzzles me is that I did not have a problem when running under 18.04 LTS; something must have changed in the transition to 24.04 LTS. Is it possible that I have moved from X-11 to Wayland? I have no idea what I was using under 18.04, I hadn’t even heard of Wayland till this week.
Because of that, I am not convinced that the stackexchange link is worth exploring - it is 11 years old. I shall have a look at the archlinux link and try to understand it.
Have you tried putting the command to open the file in gedit in a bash script, making it executable and then using an entry in cron. I use a number of these scripts using zenity and they all work. Seems like a mystery?
Yes, I’ve tried hiding gedit (and zenity) in a bash script; doesn’t work for me.
I think @Actionparsnip has pointed you in the right direction. You need to export the XAUTHORITY variable. However, the location of the xauthority file depends upon whether you are running under X11 or wayland. To find out, run:
printenv XDG_SESSION_TYPE
If running under Wayland, the following works for me. Create a script as follows and schedule it in your crontab:
#!/usr/bin/bash
export DISPLAY=:0
XAUTHORITY=$(find /run/user/“$(id -u)”/ -maxdepth 1 -type f -name .mutter-Xwaylandauth.*)
export XAUTHORITY
/usr/bin/gedit /home/user/System/Msgs/RNS
As noted in the link, under Wayland the name of the file changes every boot, so we need a way to find the name.
If your user id is always the same (eg 1000) you could just hard-code that instead.
If you are running under X11, then the file seems always to be located at /home/user/.Xauthority, so that is all you need to export.
The entry below opens the file zenity-test in cron: 04 06 * * * /home/username/zenity-test
The full content of this file is:
#!/bin/bash
PATH=/home/username
export DISPLAY=:0.0
/usr/bin/zenity --info --title “Backup Notification”
–info
–text=“Backup will run automatically in 30 minutes.
Please ensure that the removable backup device is connected.”
You need the PATH line to the directory in which the file exists. In my example it is zenity-test and is in the /home/username directory. This opens a window on the Desktop similar to the one shown above in the post by member eeickmeyer. If that doesn’t work, you have other problems.
I tried phil-hughes script. It failed with the error message
(gedit:26150): Gtk-WARNING **: 21:25:01.431: cannot open display: :0
I tried yancek’s script. it failed with error message
(zenity:26484): Gtk-WARNING **: 21:31:01.509: Failed to open display
That is the error I get if I do not export the correct xauthority file.
As requested, please provide the output of:
printenv XDG_SESSION_TYPE
and also:
printenv XAUTHORITY
printenv DISPLAY
(These should be whilst logged directly in a terminal, not by running a script from crontab.)
george~ > printenv XDG_SESSION_TYPE
wayland
george~ > printenv XAUTHORITY
/run/user/1000/.mutter-Xwaylandauth.ZTX7A3
george~ > printenv DISPLAY
:0
george~ >
Thanks, so you are running on wayland.
Sorry, I’m out of ideas. I have run that script on 3 computers running wayland, two on 25.04, one on 24.04.3, and it works on them all.
I’ve realised there might be a problem if you have copy-pasted the script.
I have used the wrong tags when quoting the script. I used Blockquote when I should have used Preformatted text (Ctrl-e). This means that the quotes are converted to smartquotes, not ordinary quotation marks.
If this is the case, please try again with the following script:
#!/usr/bin/bash
export DISPLAY=:0
XAUTHORITY=$(find /run/user/"$(id -u)"/ -maxdepth 1 -type f -name .mutter-Xwaylandauth.*)
export XAUTHORITY
echo $XAUTHORITY > /home/george/tmp.log
/usr/bin/gedit /home/george/System/Msgs/RNS >> /home/george/tmp.log 2>&1
Also, I originally put the path as “/home/user”. I assumed that you changed it to george?
Also note that I have modified the script to provide some logging. If it does not work, please provide the contents of tmp.log.
If you are using a script shown to you by another member here as above, it is best to post the contents of the script so that people can see it as there may be a typo or some other minor problems which prevents the script from functioning.
@phil-hughes
Wonderful! That worked (eventually, and I never got your logging to work).
I still don’t understand why my original approach worked with18.4 but failed with 24.04. But I am not too bothered if that remains one of life’s mysteries.