Hey Ben,
You can do this by invoking some Javascript to get the notebook name, and
then using Javascript to call Julia back again. It's kind of neat. First,
in Javascript, you can get this directly via:
IPython.notebook.notebook_name
You can pull up your browser's javascript console inside an IJulia notebook
to see that this works. Next, you can send commands to computation kernels
such as Julia and Python straight from Javascript, (Which of course, is the
foundation upon which the IJulia and IPython notebooks are built upon) so
let's set a Julia variable called notebook_name to be equal to the
Javascript variable above:
IPython.notebook.kernel.execute('notebook_name =
"'+IPython.notebook.notebook_name+'" ');
Again, you can paste that into your Javascript console to run it directly
as Javascript. After doing so, try printing the Julia variable called
notebook_name; it will have magically appeared in your workspace.
Finally, let's get Julia to output the Javascript instead of us, so we can
put it in a cell at the top of our file and have everything "just work":
display("text/html", """<script
charset="utf-8">IPython.notebook.kernel.execute('notebook_name =
"'+IPython.notebook.notebook_name+'" ');</script>""")
I realize it gets a little heady as a one-liner, so here's a notebook
<http://nbviewer.ipython.org/github/staticfloat/notebooks/blob/master/julia_notebooks/NotebookNameTest.ipynb>
showing it off in action.
-E
On Mon, Dec 22, 2014 at 3:16 PM, Ben Strowbridge <[email protected]>
wrote:
> I am working on transitioning my research group from Matlab to Julia, in
> part because of the wonderful language and because of the ability of IJulia
> notebooks to so nicely encapsulate the analysis steps along the way from
> raw data to a completed figure. To us, notebooks are a much more robust
> method to visualize intermediate results than the common approach of
> commenting out different sections of a complex mFile script. But we are
> stuck on how to discover the name of the current notebook. This is
> important because we want to paste the final analysis output into an
> electronic laboratory notebook along with an automatically generated figure
> title that contains enough information to recreate the analysis, including
> the notebook name and the current Git tag for the laboratory source file
> repository. While this seems straightforward to us, I gather from this 2012
> discussion thread related to IPython notebooks that this goes a bit against
> the grain of how notebooks were intended to be used. Is there an easy way
> to get the notebook name using Julia code or to implement the Javascript
> magics method outlined in the SO link? [Using Julia 0.3.3 on Win7x64]
>
>
>
> http://stackoverflow.com/questions/12544056/how-to-i-get-the-current-ipython-notebook-name
>