Script with xfconf-query in a crontab

About writing shell scripts and making the most of your shell
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Locked
crustyourmind

Script with xfconf-query in a crontab

Post by crustyourmind »

Hi

I'm writing a script for wallpaper under XFCE
No problem if I run it in a terminal
But i'd like to put it on a cron

This script use these command

Code: Select all

  /usr/bin/xfconf-query --channel xfce4-desktop --property /backdrop/screen0/monitor0/workspace0/last-image --set MyPicture.jpg
(the script is available here : https://www.cbiot.fr/hourWallpaper.sh )

I've read that to use it with a cron, I should use the DBUS_SESSION_BUS_ADDRESS variable to define the user environment

So I tried

Code: Select all

*/1 * * * * yourUsername source $HOME/.profile ; source $HOME/.bashrc; env DISPLAY=:0.0 /home/path/to/countdown/thScript.sh 2>/tmp/cron_errors.txt
or

Code: Select all

env DBUS_SESSION_BUS_ADDRESS=[path] xfconf-query ....
or all structures that I found on the web....
But nothing works....

So, I need help to use this script in a crontab .
All ideas is welcome,

thx
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 1 time in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
gm10

Re: Script with xfconf-query in a crontab

Post by gm10 »

None of those environment variables you are using is available to cron. Prefix this for the dbus session:

Code: Select all

env $(egrep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep -u $LOGNAME xfce-session)/environ)
crustyourmind

Re: Script with xfconf-query in a crontab

Post by crustyourmind »

Hi
Thx for your answer
I put your command line it in my bash script but but it doesn't work

In the cron error I've got this

Code: Select all

grep: /proc//environ: Aucun fichier ou dossier de ce type
So I think it doesn't find the var $LOGNAME
?
gm10

Re: Script with xfconf-query in a crontab

Post by gm10 »

It's probably xfce4-session then. Sry, I'm not on xfce. Try like this:

Code: Select all

env $(egrep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pgrep -u $LOGNAME xfce4-session)/environ)
crustyourmind

Re: Script with xfconf-query in a crontab

Post by crustyourmind »

Don't work neither
But with your help, I read another topics on the net on dbus variable and I found the command line which works

Code: Select all

  export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$(pidof -s xfce4-session)/environ |cut -d"=" -f2-)
Thanx 4 you to have help to find the way ;)
rene
Level 20
Level 20
Posts: 12240
Joined: Sun Mar 27, 2016 6:58 pm

Re: Script with xfconf-query in a crontab

Post by rene »

If you are on Mint 19 you should rather use the dbus session bus socket /run/user/$(id -u)/bus directly:

Code: Select all

export DBUS_SESSION_BUS_ADDRESS="unix:path=/run/user/$(id -u)/bus"
Also see viewtopic.php?f=42&t=279095 for this same question in a slightly different context; it also provides a method for Mint 18 which is slightly better than hardcoding e.g. "xfce4-session".
crustyourmind

Re: Script with xfconf-query in a crontab

Post by crustyourmind »

OK thx a lot ;)
Locked

Return to “Scripts & Bash”