I want to save a copy of the current notebook using Mathematica code

(* the notebook that's open is foo.nb *)
NotebookSave[SelectedNotebook[], "bar.nb"]

After execution, Mathematica would close foo.nb without saving, and open bar.nb. If I saved the path of foo.nb, close bar.nb, and reopen foo.nb, I would jump to the beginning of the file instead of having my cursor position saved.

How can I save a copy of foo.nb as bar.nb in the background, while still retaining my focus on foo.nb?


1 Answer 1


Closing foo.nb when calling NotebookSave probably was a bug that was fixed (I use Mathematica 13.2). Currently the saved notebook bar.nb is opened in the background.

If you don't want to open bar.nb use Export:

Export[SelectedNotebook[], "bar.nb"]

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.