gnome-open raises this error when run from inside tmux

Solution 1:

Instead of letting Gnome run dbus-launch to create a random D-Bus address, start dbus-daemon explicitly early in your X session startup and give it a fixed address like unix:path=~/.dbus-$HOSTNAME-$DISPLAY.

Given the information in the bug report, you may even be able to get away with unset DBUS_SESSION_BUS_ADDRESS and let applications find out the bus address from the root window properties.

As of 15.10, the per-session dbus instance is created via an Upstart session job. The job file in question is /usr/share/upstart/sessions/dbus.conf. You can replace the default random address by overriding the pre-start script stanza which specifies the address to use. Create ~/.config/upstart/dbus.override with the following:

pre-start script
    DBUS_SESSION_BUS_ADDRESS=unix:path=$HOME/.dbus-$(hostname)-$(echo $DISPLAY | sed -e s/:/%3A/)
    initctl set-env DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS
end script

The fixed address will be used after you next log in.

Solution 2:

This is apparently a bug in gconf that already has a fix (if I understood correctly from this bug report). In the meantime, the following should work around the problem:

export DBUS_SESSION_BUS_ADDRESS=$(tr '\0' '\n' < /proc/$(pgrep -U $(whoami) gnome-session)/environ|grep ^DBUS_SESSION_BUS_ADDRESS=|cut -d= -f2-)

Solution 3:

Or if as me you don't use gnome:

unset DBUS_SESSION_BUS_ADDRESS

Solution 4:

tmux can be told to always reset certain env vars:

update-environment variables

Set a space-separated string containing a list of environment variables to
be copied into the session environment when a new session is created or an
existing session is attached. Any variables that do not exist in the source
environment are set to be removed from the session environment (as if -r was
given to the set-environment command). The default is "DISPLAY SSH_ASKPASS
SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION WINDOWID XAUTHORITY".

Based on that it might be appropriate to add DBUS_SESSION_BUS_ADDRES to this option in ~/tmux.conf:

set-option -g update-environment "DBUS_SESSION_BUS_ADDRESS DISPLAY SSH_ASKPASS SSH_AUTH_SOCK SSH_AGENT_PID SSH_CONNECTION WINDOWID XAUTHORITY"

This worked for me.