diff --git a/src/schedule.cpp b/src/schedule.cpp index 2a89381..75e18b9 100644 --- a/src/schedule.cpp +++ b/src/schedule.cpp @@ -363,8 +363,14 @@ TQString Schedule::createScanScript() ts << "#!/bin/bash" << "\n"; ts << "export HOSTNAME=`hostname`" << "\n"; ts << TQString("export PATH=%1").arg(TQString(getenv("PATH"))) << "\n"; - ts << "export DCOPSERVER=`cat ${HOME}/.DCOPserver_${HOSTNAME}_:0 | grep local`" << "\n"; - ts << "export DISPLAY=:0" << "\n"; + /* The following inspired by https://unix.stackexchange.com/a/17278 */ + ts << "if [ -z \"$DISPLAY\" ]; then" << "\n"; + ts << " for d in /tmp/.X11-unix/X*" << "\n"; + ts << " do" << "\n"; + ts << " export DISPLAY=$(echo $d|sed \"s!/tmp/.X11-unix/X!:!\")" << "\n"; + ts << " done" << "\n"; + ts << "fi" << "\n"; + ts << "export DCOPSERVER=`cat ${HOME}/.DCOPserver_${HOSTNAME}_${DISPLAY} | grep local`" << "\n"; ts << "# Execution starts here" << "\n"; ts << "if [ \"$1\" = \"\" ]; then" << "\n"; ts << " exit 1" << "\n";