Launch Jupyter notebooks automatically in Windows

In latest editions of Anaconda, the installation wisely hides Python from the global path, but this also means that there are no good file associations for Python files or Jupyter notebooks.

One solution out there is nbopen. This utility launches one server and tries to reuse it with further notebooks. I have tried in the past, but it does not work if you want to work with notebooks in multiple directories. Somehow the tight permissions of Jupyter forbid it to access directories that are not inside the folder where it was initially started.

The only alternative that I have found is to build my own AutoHotKey script, which I can associate to *.ipynb files. This post documents how to do it. I assume that you have installed Miniconda for your own user and that the installation is located under %USERPROFILE%\Miniconda3

  1. Install AutoHotKey, a wonderful extension to map keys and build general scripts for Windows.
  2. Create and save the following script as start-jupyter-notebook.ahk

  3. Run the AutoHotKey compiler to convert it into an executable. I like to associate it with the Jupyter notebooks icon because then this icon is used by File Explorer. I call the executable "Open with Jupyter.exe" because it looks nice when I install it in the Start pane. The command line below one single line, sorry if it looks garbled:

    "%ProgramFiles%\AutoHotkey\Compiler\Ahk2Exe.exe" /in start-jupyter-notebook.ahk /out "Open with Jupyter.exe" /icon %USERPROFILE%\Miniconda3\Menu\jupyter.ico
    
  4. Open the properties for any Jupyter notebook (Right-click and select Properties) and click on "Change" to select the program that opens the notebooks. You may need to select "More programs" and use the explorer to find your compiled script.

The script will launch one server every time it is invoked. You can open futher files from within Jupyter using File -> Open in the Jupyter notebook menu.

When you are done, you can either kill the command line window with the Jupyter notebook or quit the server from the browser. For the latter, use File -> Open to open the Jupyter file browser and then click on Quit. You can then safely close all browser tabs.