Which GNOME version and DBUS_SESSION_BUS_ADDRESS for script called from crontab.



Hi,

I hope this question is appropriate for this list, there are so many GNOME lists. If not please advise me which list I should post it to.

I've written a Bash script for Wallpaper Clocks. The idea of these is to build a new wallpaper every minute so that the desktop wallpaper displays the current weekday, date, month, hour, and minute. See vladstudio.com if the idea appeals.

The script works fine when called from the command line, but it needs to be run every minute from crontab to function correctly and this is presenting me with 2 related problems, both resulting from crontab not logging as your own username, so it doesn't have access to X.

Firstly GNOME v2 and v3 set the wallpaper with different commands; v2 uses gconftool-2, and v3 uses gsettings. Clearly the script must determine which version is running so that the correct command can be run. The following command works fine from the command line and outputs '2' or '3' but it does not output anything when run from crontab.

gnome-session --version | grep --only-matching '[0-9]*' | head -n 1

Question 1: How do I determine which GNOME version is running from within the script when it is run from crontab regardless of which flavour of Unix/Linux is running?


Secondly in order to set the wallpaper using gconftool-2 (and I assume also with gsettings?, though this is untested at the moment) when the script is called from crontab the environment variable DBUS_SESSION_BUS_ADDRESS needs to be set.

I have found a method of doing this online, which works with GNOME v2 on my Ubuntu desktop (still using Lucid).

It gets the nautilus process ID, then accesses that process's /proc/Nautilus_ID/ directory searching the 'environ' file for the DBUS_SESSION_BUS_ADDRESS.

nautilus_pid=$(pgrep -u $LOGNAME -n nautilus)
dbusSessionBusEnvVar=$(tr '\0' '\n' < /proc/$nautilus_pid/environ | grep '^DBUS_SESSION_BUS_ADDRESS=')
eval "$dbusSessionBusEnvVar"
export DBUS_SESSION_BUS_ADDRESS

This does not seem a very elegant solution.

Question 2: Is there a generic way to get and set the value of DBUS_SESSION_BUS_ADDRESS from within the script when called from crontab which will work with both Gnome v.2 and v.3 and regardless of which flavour of Unix/Linux is running?

Many thanks everyone. Sorry if these are real newbie questions, I'm a bit of a GNOME newbie (at least the technical aspects of it, I've been running it as my desktop manager for years.)

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]