-
Notifications
You must be signed in to change notification settings - Fork 5
/
adntree.py
executable file
·48 lines (36 loc) · 1.03 KB
/
adntree.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
45
46
47
#!/usr/bin/env python
## adntree.py
#########################################
## With a link to an ADN post on the clipboard this
## opens it up in Safari in TreeView.
## Usually used in concert with Keyboard Maestro to open
## the selected post in TreeView with a single key.
import optparse
import re
import sys
from appscript import *
from osax import OSAX
def opentreeapp(post):
Safari = app(u'/Applications/Safari.app')
Safari.activate()
Safari.make(new=k.document)
url = "http://treeview.us/home/thread/"+post+"#"+post
Safari.documents[0].URL.set(url)
def getpostnum(text):
try:
lines = text.split("\n")
l = lines[0].strip()
match = re.match(r'https://alpha.app.net/.*/post/(\d+)', l)
post = match.group(1)
except:
post = ""
print "Invalid Format"
return post
def main():
sa = OSAX()
url = sa.the_clipboard()
print url
post = getpostnum(url)
opentreeapp(post)
if __name__ == '__main__':
main()