Using awesome-client outside X (dbus)

Original solution here: 

Problem
As you may know awesome-client uses dbus to send messages to existing instance of awesome running. It works perfectly when you run it from your X session, but sometimes you want more than that. For example, send a message to your Awesome from a ssh-session. Or setup a daemon that notifies Awesome about some events.

Solution
Dbus relies on a parameter called DBUS_SESSION_BUS_ADDRESS. In your X session you have this parameter defined, outside of it this parameter is blank. Fortunately dbus stores the parameters for its session in directory $HOME/.dbus/session-bus.

What you do now is you create a wrapper-script somewhere and put this code there:

#!/bin/bash if -z "$DBUS_SESSION_BUS_ADDRESS"  ; then # Looks like we are outside X      dbus_file=$(ls $HOME/.dbus/session-bus/ -t1 | head -1) # Get the latest file in session-bus directory . "$HOME/.dbus/session-bus/$dbus_file" && export DBUS_SESSION_BUS_ADDRESS # and export a variable from it fi  /usr/bin/awesome-client

Alternatively, if you get spawned without any environment (e.g. udevil's validate_exec does this, HOME is not even defined), you can copy the enviroment from the awesome process), like so:

#!/bin/bash if -z "$DBUS_SESSION_BUS_ADDRESS"  ; then # Looks like we are outside X      eval $(tr '\0' '\n' < /proc/$(pgrep awesome | head -1 )/environ | sed -e 's/^/export /') #export all environment variables fi /usr/bin/awesome-client

Or, if you want to allow root to use awesome-client also, you would have to impersonate the user:

#!/bin/bash AWESOME_CLIENT=awesome-client AWESOME_PID=$(pgrep awesome | head -1 ) if -z "$DBUS_SESSION_BUS_ADDRESS"  ; then # Looks like we are outside X      eval $(tr '\0' '\n' < /proc/${AWESOME_PID}/environ | sed -e 's/^/export /') #export all environment variables fi AWESOME_PID_OWNER=$(stat -c %U /proc/${AWESOME_PID}) if $EUID -ne 0 ; then # we are not root eval $AWESOME_CLIENT else su $AWESOME_PID_OWNER -c $AWESOME_CLIENT fi

Now you can call this script just like you call the original awesome-client, but this script works also in none-X sessions.

Give it a try, try executing this from your tty1, for example:

echo 'naughty.notify({ text = "hello from tty" })' | ~/myawesomeclient.sh

On your X screen a naughty box should pop up.