Is there any way to securely stick a notebook window (e.g. a dialog) on screen that it cannot be closed/removed/hidden by any of the standard OS shortcuts, like AltF4 or AltTab under Windows? The ideal solution would allow me to specify a range of key-combinations that can be used, and block any other, though it would not be a problem to block all keyboard input, as there are other ways to close a modal dialog.

I have a feeling that this cannot be done entirely from under Mathematica, though I'll give it a go. You can experiment with the following example:

CreateDialog[{TextCell["Click OK to close"], DefaultButton[]}, Modal -> True]

Purpose: I'm doing some experimentation on humans in Mathematica, and since this species is known by its extensive explorative behaviour (i.e. pushing all buttons) and the ability to ruin everything, I want to make the experiment-gui foolproof so that they can't remove it from the screen. This is a must, as it could happen that they hit AltF4 (accidentally or intentionally) and quit at the middle of a test, rendering any saved data useless.

  • $\begingroup$ I guess you figured out that WindowFrameElements -> {} doesn't prevent Alt-F4 from working. $\endgroup$
    – Szabolcs
    Apr 19, 2012 at 15:14
  • $\begingroup$ Not sure this is a Mathematica-specific question? Maybe people over on SuperUser might have ideas that can then be implemented in MMA? $\endgroup$
    – Eli Lansey
    Apr 19, 2012 at 15:22
  • $\begingroup$ @Szabolcs Setting WindowFrameElements -> {} does prevent Cmd-w from closing the notebook on OS X. $\endgroup$
    – Heike
    Apr 19, 2012 at 15:34
  • $\begingroup$ I now how to do it in AutoHotKey, though I would prefer a domestic solution. $\endgroup$ Apr 19, 2012 at 15:36
  • $\begingroup$ @Heike that doesn't help for Alt-F4 $\endgroup$
    – Eli Lansey
    Apr 19, 2012 at 15:41

1 Answer 1


Not 100% solution, but this may work. Define:

dialog := 
 CreateDialog[{TextCell["Click OK to close"], DefaultButton[]}, 
  Modal -> True, NotebookEventActions -> {"WindowClose" :> dialog}]

Then call:


At least, it reappears :)

  • 1
    $\begingroup$ Devilish workaround :) But unfortunately it does not prevent accidental Alt+Tab changes and similar non-invasive key combinations which simply just hide the window. $\endgroup$ Apr 19, 2012 at 20:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.