DBUS_SESSION_BUS_ADDRESS – Determine from Outside X Session

d-buslinux-mintssh

I've got mate-screensaver installed on a machine running Linux Mint 16. On that machine, I can open up a terminal and query the state of the screensaver:

dan@box1 ~ $ echo $DISPLAY
:0.0
dan@box1 ~ $ mate-screensaver-command -q
The screensaver is inactive
The screensaver is not inhibited

This all works fine and makes sense. However, when I SSH into that same machine, I don't get the results I expect:

dan@box2 ~ $ ssh box1
dan@box1 ~ $ export DISPLAY=:0.0
dan@box1 ~ $ echo $DISPLAY
:0.0
dan@box1 ~ $ mate-screensaver-command -q
** Message: Screensaver is not running!

This same method works on all my other computers, all running various versions of Mint. Nothing strange is getting logged to my ~/.xsession-errors.

After reading this answer, I discovered that setting my DBUS_SESSION_BUS_ADDRESS to unix:abstract=/tmp/dbus-ToCuEUyLn0,guid=9296df6ba791b044d4236e45545fbe55 (its value in a local terminal) makes things work as I expect over SSH. However, ~/.dbus/session-bus/*-0 contains a different value, which doesn't work, and I can't find a file containing the correct value for that variable.

Why would one of my machines require that value to be changed, while the rest don't? If that behavior makes sense or is complicated to correct, where else would I look to find the correct value for that variable?

Best Answer

I use this to get it, but it relies on a running session:

if [[ -z $DBUS_SESSION_BUS_ADDRESS ]]; then
    pgrep "gnome-session" -u "$USER" | while read -r line; do
        exp=$(cat /proc/$line/environ | grep -z "^DBUS_SESSION_BUS_ADDRESS=")
        echo export "$exp" > ~/.exports.sh
        break
    done
    if [[ -f ~/.exports.sh ]]; then
        source ~/.exports.sh
    fi
fi

Change 'gnome'to any other session you have (it has to be running).

Related Question