martin-ueding / thinkpad-scripts

Screen rotation, docking and other scripts for ThinkPad® X220 and X230 Tablet
Other
132 stars 23 forks source link

gsettings needs DBUS_SESSION_BUS_ADDRESS of current user #73

Open monte-monte opened 10 years ago

monte-monte commented 10 years ago

In order to make changes with gsettings or dconf you shoul have "DBUS_SESSION_BUS_ADDRESS" variable of current user. Since scripts are called from root they don't have any dbus session address, and variable in gsettings can't be changed.

You can read about this here: http://stackoverflow.com/questions/10374520/gsettings-with-cron/10390963#10390963 or here: www.unix.com/shell-programming-scripting/203631-dbus_session_bus_address-script-called-crontab.html for example.

I used this lines in my hooks:

PID=$(pgrep -u $LOGNAME gnome-session)  # instead of 'gnome-session' it can be also used 'nautilus' or 'compiz' or the name of a process of a graphical program about that you are sure that is running after you log in the X session
export DBUS_SESSION_BUS_ADDRESS=$(grep -z DBUS_SESSION_BUS_ADDRESS /proc/$PID/environ|cut -d= -f2-)
martin-ueding commented 10 years ago

That is cool! We had problems with the environment variables all along. This is probably a good idea to include.