Script with xfconf-query in a crontab

Forum rules
Before you post please read how to get help
Post Reply
crustyourmind
Level 1
Level 1
Posts: 5
Joined: Thu Mar 29, 2018 1:06 pm
Location: France

Script with xfconf-query in a crontab

Post by crustyourmind » Tue Oct 16, 2018 2:23 pm

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
Linux Mint Sylvia Cinnamon

gm10
Level 13
Level 13
Posts: 4719
Joined: Thu Jun 21, 2018 5:11 pm

Re: Script with xfconf-query in a crontab

Post by gm10 » Tue Oct 16, 2018 3:42 pm

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
Level 1
Level 1
Posts: 5
Joined: Thu Mar 29, 2018 1:06 pm
Location: France

Re: Script with xfconf-query in a crontab

Post by crustyourmind » Wed Oct 17, 2018 5:46 am

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
?
Linux Mint Sylvia Cinnamon

gm10
Level 13
Level 13
Posts: 4719
Joined: Thu Jun 21, 2018 5:11 pm

Re: Script with xfconf-query in a crontab

Post by gm10 » Wed Oct 17, 2018 6:03 am

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
Level 1
Level 1
Posts: 5
Joined: Thu Mar 29, 2018 1:06 pm
Location: France

Re: Script with xfconf-query in a crontab

Post by crustyourmind » Wed Oct 17, 2018 8:30 am

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 ;)
Linux Mint Sylvia Cinnamon

rene
Level 8
Level 8
Posts: 2392
Joined: Sun Mar 27, 2016 6:58 pm

Re: Script with xfconf-query in a crontab

Post by rene » Wed Oct 17, 2018 4:02 pm

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
Level 1
Level 1
Posts: 5
Joined: Thu Mar 29, 2018 1:06 pm
Location: France

Re: Script with xfconf-query in a crontab

Post by crustyourmind » Fri Oct 19, 2018 1:04 pm

OK thx a lot ;)
Linux Mint Sylvia Cinnamon

Post Reply

Return to “Scripts & Bash”