codeblog code is freedom — patching my itch

August 5, 2008

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
else
    export \$(xargs -0 -n1 /proc/\$PID/environ | grep ^DBUS_SESSION_BUS_ADDRESS=)
    audacious --play-pause
fi"

(Updated to shorter version, thanks Kirikaza.)

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

4 Comments

  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 — January 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 — January 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 — February 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 |
    grep ^DBUS_SESSION_BUS_ADDRESS=)

    Comment by Kirikaza — April 3, 2010 @ 9:08 am

Powered by WordPress