diff --git a/DBus-service.md b/DBus-service.md index b8785c6..0ff8918 100644 --- a/DBus-service.md +++ b/DBus-service.md @@ -41,6 +41,37 @@ export DBUS_LAUNCHD_SESSION_BUS_SOCKET=$(launchctl getenv DBUS_LAUNCHD_SESSION_B Note that this will work only from a normal Macintosh desktop session. +#### MacOS and SSH + +As mentioned, the command lines above work only from a normal Macintosh desktop session, because `launchctl` is not available via SSH. + +To work around this problem, there are two cases: + +**Case 1: dbus is already running** + +You can determine if dbus is already running with the command: + +``` +ps auxw|grep dbus|grep $(whoami)|grep session +``` + +If it is running, you can rely on the notion that the most recent listener in /private/tmp is assigned to this version of dbus. (This might not be 100% reliable in the future, so proceed at your own risk.) Use the command: + +``` +export DBUS_LAUNCHD_SESSION_BUS_SOCKET=$(find /private/tmp -type s -name unix_domain_listener -print0 | xargs -0 ls -rt|tail -n 1) +``` + +**Case 2: dbus is not running** + +If you have determined that dbus is not running, you can choose your own address and set DBUS_LAUNCHD_SESSION_BUS_SOCKET to match it. For example, to use $HOME/Library/Caches/dbus/bus (make sure the directory exists and has permissions 0700): + +``` +mkdir -p $HOME/Library/Caches/dbus +chmod 0700 $HOME/Library/Caches/dbus +DBUS_LAUNCHD_SESSION_BUS_SOCKET=$HOME/Library/Caches/dbus/bus +/usr/local/Cellar/dbus/1.12.20/bin/dbus-daemon --nofork --session --address=$DBUS_LAUNCHD_SESSION_BUS_SOCKET +``` + #### MacOS and dbus-send In order for `dbus-send` to work correctly, it needs to either be started from a terminal within a normal Mac desktop session, or it needs to have the environment variable `DBUS_SESSION_BUS_ADDRESS` set correctly.