-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsafari_to_marsedit.py
executable file
·60 lines (40 loc) · 1.53 KB
/
safari_to_marsedit.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
48
49
50
51
52
53
54
55
56
57
58
59
60
#!/usr/bin/python
# -*- coding: utf-8 -*-
### readkit_to_marsedit.py
### Creates a post in MarsEdit for the current tab in Safari
from appscript import *
import sys
import time
from osax import OSAX
from titlecase import titlecase
def get_safari_info():
"""Activates ReadKit and gets the title and url for the selected post"""
# activating Safari's not really needed but makes debugging easier
app(u'Safari').activate()
title = app(u'Safari').windows[1].current_tab.name.get()
link = app(u'Safari').windows[1].current_tab.URL.get()
return [title, link]
def create_marsedit_post(title, link):
"""Creates a MarsEdit post with given html code leaving in rtf mode"""
# create a new Mars Edit document
ME = app(u'/Applications/MarsEdit.app')
ME.activate()
newdoc = ME.make(new=k.document)
# make with category of sideblog (Where I put short entries)
newdoc.category_names.set(["Sideblog"])
# set the body text
html = '<a href="{}">{}</a>'.format(link, title)
newdoc.current_text.set(html)
# set the post title
post_title = title.split("\n")[0] # get rid of multiline titles
post_title = titlecase(title) # title case the title
newdoc.title.set(post_title) # note - must be done last as changing title changes document reference
def main():
title,link = get_safari_info()
create_marsedit_post(title, link)
def test():
print get_safari_info()
if __name__ == '__main__':
main()
#test()
sys.exit(0)