AppleScript running Ipython Notebooks trough double click
Here’s some AppleScript magic to have .ipnb
-files runnable with a double click, like they should.
-
Fire up
AppleScript Editor
(found in/Applications/Utilities/
) and paste the following code:on run set startPath to "" --change to your prefered path, mine was /Users/max/Dropbox/Dokument/Python tell application "Terminal" activate do script with command "cd " & startPath & " && ipython notebook" end tell end run on open the_files repeat with i from 1 to the count of the_files tell application "Finder" set p to POSIX path of (item i of the_files) end tell tell application "Terminal" activate do script with command "ipython notebook " & p end tell end repeat end open
- Save as a
program
preferably in your/Applications/
folder. - Press
Cmd+i
on any.ipnb
-file. - Under
Open with
select your created program. - Press
Change all...
- Profit!?!?
They should now open in the browser. If you just want to start Ipython Notebook you can just double click it like any program (and of course put it in your dock). Be sure to set the variable setPath
to something like /Users/max/Dropbox/Dokument/Python
so you’re at your prefered path right from the start.
And while we’re at it, here’s some code for a drag and drop AppleScript converting .ipnb
to markdown .md
:
on open the_files
repeat with i from 1 to the count of the_files
tell application "Finder"
set filePath to POSIX path of (item i of the_files)
end tell
tell application "Terminal"
activate
set parentFolder to POSIX path of ((the_files as text) & "::")
do script with command "cd " & parentFolder & " && ipython nbconvert --to markdown " & filePath
end tell
end repeat
end open