#!/bin/bash

X_USER=$(ps au | grep startx | awk '{print $1}')

# Default display on current host
export DISPLAY=':0.0'

# Switch to X user if necessary
if [ "$X_USER" != "$USER" ]
then
    CMD="su $X_USER -c '$@'"
 else
    CMD="$@"
fi

eval $CMD
