How to run Javascript in Notebook 7?

I have a fairly complicated Jupyter Notebook that I perfected over time. Now the transition to Notebook 7 broke it.

Essentially what I want to do is the following:

  1. Force a save operation of the current notebook
  2. Create a copy of the saved notebook with a different name in a different directory (using shutil command)
  3. Use nbconvert to convert the notebook copy from .ipynb to .html

For step 1, I am using the following:

from IPython.display import Javascript
Javascript(‘’‘IPython.notebook.save_notebook()’‘’)

Now this fails with

Javascipt Error: IPython is not defined

Sorry, you have posted a case of making an XY problem.
Specifically your title and post text don’t match. Title: ‘How to run Javascript in Notebook 7?’. Synopsis of primarily goal from your post text: " Essentially what I want to do is the following: Force a save operation of the current notebook." As spelled out in that link discussing the ‘XY problem’ concept, it is always best to search & research, and then eventually post, if there is no solution already out there, about what you want to do overall, and avoid posting focused on a step in the path to how you think you could ultimately accomplish it. Others cannot find the pertinent solution later if the title doesn’t relate to what was really trying to be achieved.

What you seem to really want to do to save the current notebook is covered here in answer to ‘How to cause Jupyter Lab to save notebook (programmatically)’ using ipylab which will work in current JupyterLab v4+ and Jupyter Notebook 7+ tech. Keep in mind that one of the big changes in regards to Jupyter Notebok 7+, is the switch to building on JupyterLab components for both current JupyterLab and Jupyter Notebook going forward. This means a lot of solutions you’ll seek out for Jupyter Notebook 7+ are often covered under earlier posts about how to do things in JupyterLab in the last few years.

I’ll note there is also 'docmanager:save-as' that you can see if you run app.commands.list_commands() (after running the first two lines of the code there). I believe you could perhaps use that to replace your approach to using shutil for step #2.

Yes, I have posted a “case of making an XY problem” because the problem I want to solve has multiple steps and I thought I get started with step 1 first.

Anyway, thanks for the hint. It seems to work.