Martin,
I hadn't meant that that was the only way to script it. Sorry I wasn't more clear on that.
This would be a more complete script:
# check for kdesu or gksu and setup/or run XUFOO
#=================================================
if [ ! -e $XUFOO ];then
if [ -r /usr/bin/gksu ]; then WMSUDO=/usr/bin/gksu; fi
if [ -r /usr/lib/kde4/libexec/kdesu ]; then WMSUDO=/usr/lib/kde4/libexec/kdesu; fi
# setup XUFOO
echo "#"'!/bin/bash' > $XUFOO
if [ "$UID" != "0" ]; then echo $WMSUDO foo-me >> $XUFOO; else echo foo-me >> $XUFOO; fi
chmod a+x $XUFOO
$XUFOO &
exit 0
fi
Note the check for gksu or kdesu establishes whether the environment is kde or another.
As an example, a check to discover whether LXDE is the DE and therefore to use lxde-logout would be something like:
if [ ! -e $XUFOO ];then
if [ -r /usr/bin/lxde-logout ]; then WMSUDO=/usr/bin/lxde-logout; fi
To write a script to discover whether a DE is installed, you would need to run a simple script that would check for something specific to that DE. As in the above example, you discover the the DE is LXDE and follow that with the command to use lxde-logout.
Remember, these are only examples. You can use the basic structure to create your own checks.