How to write code to close the current open Notebook document after 10 seconds?

SessionSubmit[ScheduledTask[NotebookClose[], Quantity[10, "Seconds"]]]

I expected the above execution, but it is not. What is the problem?


1 Answer 1


Your task is held and executed asynchronously so once it gets to the Kernel it won't 'remember' which notebook it was sent from. You need to send it with that information:

With[{nb = EvaluationNotebook[]}, 
 SessionSubmit[ScheduledTask[NotebookClose@nb, Quantity[10, "Seconds"]]]
  • $\begingroup$ I solved it using 'SessionTime'. The answer is excellent, too! Thank you! Dynamic[ If[Floor[SessionTime[]] > 600, NotebookClose[], Row[{ Floor@SessionTime[], "/600"}] ], UpdateInterval -> 1] $\endgroup$
    – Milk
    Nov 22, 2023 at 7:51

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.