codeblog code is freedom — patching my itch


dbus session access from remote

Filed under: Blogging,Networking,Ubuntu — kees @ 8:49 pm

In order to turn off the music playing on my desktop (in audacious) from my laptop in another room, I must figure out the DBUS session, and set it up before using the audacious session management control (like “--play-pause“).

$ ssh MACHINE "set -x
export DISPLAY=:0.0
PID=\$(pidof audacious)
if [ -z \"\$PID\" ]; then
    rhythmbox-client --pause
    export \$(xargs -0 -n1 /proc/\$PID/environ | grep ^DBUS_SESSION_BUS_ADDRESS=)
    audacious --play-pause

(Updated to shorter version, thanks Kirikaza.)

© 2008 – 2010, Kees Cook. This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 License.
Creative Commons License


  1. Useful tip, thanks!

    Do you know how to pull the DBUS_SESSION_BUS_ADDRESS for an active user, as opposed to a running program?

    I’d like to start a remote shell on demand that attaches to my remote dbus session (similar to above), but I don’t know what programs might be running at that time…

    Comment by Sean — 1/6/2009 @ 9:48 am

  2. If the remote user is logged into X, you have all kinds of things. Use “pstree -lup” to see them. Probably the best might be x-session-manager, nautilus, or gnome-panel.

    Comment by kees — 1/6/2009 @ 10:52 am

  3. which language is it? if i want to make a script out of it?
    #!/bin/bash doesnt work…

    Comment by Grunsch — 2/8/2009 @ 3:39 am

  4. You can replace cat /proc/\$PID/environ | xargs -0 -n1 with xargs -0 -n1 </proc/\$PID/environ. Also you can use the variable name DBUS_SESSION_BUS_ADDRESS just from the found line (without cutting). And the last tip: you can use a pipe symbol at the end of line like a “\”. So, a shorter variant:

    export \$(xargs -0 -n1 </proc/\$PID/environ |

    Comment by Kirikaza — 4/3/2010 @ 9:08 am

Leave a Reply

Your email address will not be published. Required fields are marked *

Powered by WordPress