-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathstartnotebook.py
executable file
·44 lines (30 loc) · 1.14 KB
/
startnotebook.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python
import sys
from appscript import *
import time
from plumbum import BG, local
from plumbum.cmd import grep, ps, wc
def check_notebook():
chain = ps["aux"] | grep["ipython notebook"]
result = chain()
if "/usr/local/bin/ipython notebook" in result:
print "Notebook Running"
return True
return False
def start_notebook():
#command = "/usr/local/bin/ipython notebook --pylab inline --no-browser --NotebookManager.notebook_dir='/Users/clarkgoble/projects'&"
ipython = local["/usr/local/bin/ipython"]
ipython["notebook", "--pylab", "--no-browser", "--NotebookManager.notebook_dir='/Users/clarkgoble/projects'"] & BG
# takes a little bit of time to startup - want to pause before attaching
time.sleep(2)
def attach_notebook():
C = app(u'/Applications/Google Chrome.app')
C.make(new=k.window)
C.windows[1].active_tab.URL.set("http://127.0.0.1:8888")
C.activate()
def main():
if not check_notebook():
start_notebook()
attach_notebook()
if __name__=='__main__':
sys.exit(main())