I'm not at a tc machine at the moment, but I believe the exit dialogue launched by the jwm tray "X" is a script executable by busybox sh.
You could probably write something in C (like curaga's watcher app in the jwm tray) or bash, perl, python, etc - as long as you have the appropriate extension loaded.