Mac application for double-clicking to open Jupyter Notebook (* .ipynb)

Overview

Create an application ** Jupyter Launcher.app ** to open Jupyter Notebook (\ * .ipynb) by double-clicking using Automator on Mac. Personally based on buq's original idea (double-click to open ipython notebook file @ OS X) Make some changes for the features you want to add to. I'm rewriting it in Python.

dock_screenshot.png

Additional features and changes

Minor improvements

Creation procedure

  1. Start Automator.app, select ** New Application ** and start creating
  2. Select ** Run Shell Script ** from Actions
  3. Select ** / usr / bin / python ** as the shell
  4. Select ** as an argument for the input delivery method
  5. Enter the following Python script into the window
  6. Save as Jupyter Launcher.app in / Applications
  7. Set the icon as you like and complete

automator_screenshot.png

Python script

** 2017.01.14: ** Updated script (no functional changes)

jupyter_launcher.py


# coding: utf-8

"""Script for the Jupyter Launcher Application."""

import os
import sys
import time
import webbrowser
from subprocess import Popen, PIPE


def listened(port):
    """Check if the spacified port is listened or not."""
    cmd = "lsof -i :{} | grep 'LISTEN'"
    proc = Popen(cmd.format(port), stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True)
    return bool(proc.communicate()[0])


def launch_jupyter(port):
    """Launch a Jupyter Notebook Server with the spacified port."""
    cmd = "bash -cl 'jupyter-notebook ~/ --port={} --no-browser &' > /dev/null 2>&1"
    proc = Popen(cmd.format(port), stdin=PIPE, stdout=PIPE, stderr=PIPE, shell=True)
    proc.communicate()


if __name__ == '__main__':
    PORT = 8888
    ipynbs = sys.argv[1:]

    if not listened(PORT):
        launch_jupyter(PORT)

    while not listened(PORT):
        time.sleep(0.5)

    if ipynbs:
        for ipynb in ipynbs:
            url = 'http://localhost:{}/notebooks/{}'
            path = os.path.relpath(ipynb, os.environ['HOME'])
            webbrowser.open(url.format(PORT, path))
    else:
        url = 'http://localhost:{}/tree'
        webbrowser.open(url.format(PORT))

References

Recommended Posts

Mac application for double-clicking to open Jupyter Notebook (* .ipynb)
Convert jupyter notebook .ipynb files to python executable .py files
Double-click to open ipynb file (Mac, Anaconda virtual environment)
Next to Excel, for the time being, jupyter notebook
Shortcut key for Jupyter notebook
Introduced Jupyter Notebook to CentOS 7
How to use Jupyter Notebook
How to see the contents of the Jupyter notebook ipynb file
Snippet settings for python jupyter notebook
Jupyter Notebook essential for software development
Generate Jupyter notebook ".ipynb" in Python
Install Anaconda on Mac and upload Jupyter (IPython) notebook to Anaconda Cloud
Easy to use Jupyter notebook (Python3.5)
Try running Jupyter Notebook on Mac
Specify the browser to use with Jupyter Notebook. Especially Mac. (And Vivaldi)
Allow Jupyter Notebook to embed audio data in HTML tables for playback
I want to display an image on Jupyter Notebook using OpenCV (mac)
Markdown to get Jupyter notebook results to Qiita
Jupyter Notebook extension, nbextensions settings for myself
I want to blog with Jupyter Notebook
How to execute commands in jupyter notebook
How to use jupyter notebook with ABCI
Jupyter Notebook Basics of how to use
How to use Jupyter notebook [Super Basic]
Install and set Jupyter Notebook to create a study note creation environment [Mac]
Library for "I want to do that" of data science on Jupyter Notebook
How to debug with Jupyter or iPython Notebook
[Jupyter Notebook / Lab] 3 ways to debug on Jupyter [Pdb]
Data analysis for improving POG 2 ~ Analysis with jupyter notebook ~
Wait for another window to open in Selenium
[Introduction to Udemy Python3 + Application] 43. for else statement
Jupyter Notebook Settings-How to use (EC2 Amazon Linux 2)
Unable to open file for writing About sudo
Remotely open Jupyter notebook launched on the server
jupyter notebook does not start on mac fish
What to do if your Jupyter Notebook for beginners asks for a password or token