├── ConvertMarkdown.py ├── ConvertTwitter.py ├── CopyWebpageTitle.py ├── Encode HTML.py ├── ImagesHTML.py ├── MarkdownCallback.py ├── README.md ├── ScreenshotsClipboard.py ├── ScreenshotsControl.py └── ScreenshotsSimple.py /ConvertMarkdown.py: -------------------------------------------------------------------------------- 1 | import markdown 2 | import clipboard 3 | 4 | 5 | input_file = clipboard.get() 6 | 7 | s = input_file 8 | 9 | 10 | md = markdown.Markdown() 11 | html = md.convert(s) 12 | 13 | print html 14 | 15 | clipboard.set(html) 16 | -------------------------------------------------------------------------------- /ConvertTwitter.py: -------------------------------------------------------------------------------- 1 | import clipboard 2 | import console 3 | import webbrowser 4 | 5 | mytext = clipboard.get() 6 | mytext = mytext.replace('https://twitter.com/', 'tweetbot://') 7 | mytext = mytext.replace('statuses', 'status') 8 | mytext = mytext.replace('http://twitter.com/', 'tweetbot://') 9 | mytext = mytext.replace('http://mobile.twitter.com/', 'tweetbot://') 10 | mytext = mytext.replace('https://mobile.twitter.com/', 'tweetbot://') 11 | 12 | console.clear() 13 | print mytext 14 | 15 | webbrowser.open(mytext) 16 | -------------------------------------------------------------------------------- /CopyWebpageTitle.py: -------------------------------------------------------------------------------- 1 | import urllib 2 | import clipboard 3 | import bs4 4 | import webbrowser 5 | import console 6 | 7 | link = clipboard.get() 8 | 9 | soup = bs4.BeautifulSoup(urllib.urlopen(link)) 10 | clipboard.set(soup.title.string +' '+ link) 11 | text = clipboard.get() 12 | console.clear() 13 | print(text) 14 | -------------------------------------------------------------------------------- /Encode HTML.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import clipboard 3 | text = clipboard.get() 4 | from bs4.dammit import EntitySubstitution 5 | print EntitySubstitution.substitute_html(text) 6 | -------------------------------------------------------------------------------- /ImagesHTML.py: -------------------------------------------------------------------------------- 1 | # Uses direct link to image in clipboard to generate HTML code suitable for MacStories 2 | # Should work just about anywhere else though. 3 | # Please note: script will ask for image Title and Alt attributes using an input_alert from console. 4 | 5 | import clipboard 6 | import console 7 | 8 | image = clipboard.get() 9 | 10 | alts = console.input_alert("Image Alt", "Type alt below") 11 | title = console.input_alert("Image Title", "Type title below") 12 | 13 | final = "" 14 | 15 | print final 16 | clipboard.set(final) 17 | -------------------------------------------------------------------------------- /MarkdownCallback.py: -------------------------------------------------------------------------------- 1 | # You can change the URL for webbrowser.open at the end to any app you like 2 | # The app has to support a URL scheme that lets you add output to a document 3 | # Text is set to clipboard, then encoded to utf-8 to avoid Unicode errors 4 | # In Byword's case, the output is passed along to a new text file after Markdown conversion to HTML 5 | 6 | 7 | import webbrowser 8 | import markdown 9 | import clipboard 10 | import urllib 11 | 12 | 13 | input_file = clipboard.get() 14 | 15 | s = input_file 16 | 17 | 18 | md = markdown.Markdown() 19 | html = md.convert(s) 20 | 21 | clipboard.set(html) 22 | 23 | s = clipboard.get() 24 | s = urllib.quote(s.encode('utf-8')) 25 | 26 | webbrowser.open('byword://new?text=' + s) 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | pythonista-scripts 2 | ================== 3 | 4 | Python scripts to use in [Pythonista](http://omz-software.com/pythonista/ "Pythonista - omz:software") for iOS. Mostly Markdown-related. 5 | 6 | Thanks to Pythonista developer [Ole Zorn](https://twitter.com/olemoritz "Ole Zorn (olemoritz) on Twitter") for feedback and input. 7 | 8 | #### ConvertMarkdown 9 | 10 | A simple Markdown converter for the clipboard contents. 11 | 12 | 13 | #### ConvertTwitter 14 | 15 | Converts twitter.com URLs (either with http or https, mobile.twitter.com or regular format) to "single status" links for Tweetbot. 16 | 17 | 18 | #### CopyWebpageTitle 19 | 20 | Copy a URL's page title and return title + link format. Example: Tweetbot for Mac Review http://www.macstories.net/news/tweetbot-for-mac-review/ 21 | 22 | #### Encode HTML 23 | 24 | A simple HTML encoder for clipboard contents. 25 | 26 | #### ImagesHTML 27 | 28 | Uses direct link to image in clipboard to generate HTML code suitable for a center-aligned image with Title and Alt attributes. 29 | 30 | #### MarkdownCallback 31 | 32 | Same as ConvertMarkdown, but also pastes output into a new Byword document using Byword's URL scheme. 33 | 34 | #### ScreenshotsClipboard 35 | 36 | Imports two screenshots (iPhone 5) from the iOS clipboard and creates a single image. Based on: http://www.macstories.net/tutorials/a-better-way-to-combine-iphone-screenshots-with-keyboard-maestro/ 37 | 38 | #### ScreenshotsControl 39 | 40 | Takes two iPhone 5 screenshots, places them side-by-side in a single image set to the clipboard. Unlike ScreenshotsClipboard, this script lets you set the placement of screenshots in the final image. 41 | 42 | #### ScreenshotsSimple 43 | 44 | Same as ScreenshotsClipboard, but images are fetched from Pythonista's image manager. 45 | 46 | -------------------------------------------------------------------------------- /ScreenshotsClipboard.py: -------------------------------------------------------------------------------- 1 | # Imports two screenshots (iPhone 5) from the iOS clipboard and creates a single image 2 | # Based on: http://www.macstories.net/tutorials/a-better-way-to-combine-iphone-screenshots-with-keyboard-maestro/ 3 | # Images are pasted in order of Photos.app 4 | 5 | 6 | import clipboard 7 | import Image 8 | 9 | im1 = clipboard.get_image(idx=0) 10 | im2 = clipboard.get_image(idx=1) 11 | _1 = im1.resize((366,650),Image.ANTIALIAS) 12 | _2 = im2.resize((366,650),Image.ANTIALIAS) 13 | background = Image.new('RGBA', (746,650), (255, 255, 255, 255)) 14 | background.paste(_1,(0,0)) 15 | background.paste(_2,(380,0)) 16 | background.show() 17 | 18 | clipboard.set_image(background) 19 | -------------------------------------------------------------------------------- /ScreenshotsControl.py: -------------------------------------------------------------------------------- 1 | # Takes two iPhone 5 screenshots, places them side-by-side in a single image set to the clipboard. 2 | # Python version of this Keyboard Maestro macro: http://www.macstories.net/tutorials/a-better-way-to-combine-iphone-screenshots-with-keyboard-maestro/ 3 | # Unlike ScreenshotsClipboard, this script lets you set the placement of screenshots in the final image 4 | # You can, for instance, decide to paste the first Photos.app screenshot (index starts at 0) as the second image on the right 5 | # If you choose "the second image", the second file copied in Photos.app will be pasted first. 6 | # Inspired by Gabe Weatherhead: http://www.macdrifter.com/pythonista-app-from-toy-to-tool.html 7 | 8 | import clipboard 9 | import Image 10 | 11 | 12 | im1 = clipboard.get_image(idx=0) 13 | im2 = clipboard.get_image(idx=1) 14 | _1 = im1.resize((366,650),Image.ANTIALIAS) 15 | _2 = im2.resize((366,650),Image.ANTIALIAS) 16 | background = Image.new('RGBA', (746,650), (255, 255, 255, 255)) 17 | 18 | print "Which image goes on the left? (in Photos.app order)" 19 | 20 | print "[1] The first image" 21 | 22 | print "[2] The second image" 23 | 24 | formatType = raw_input("Select an image: ") 25 | 26 | if formatType == "x": 27 | 28 | print "Exited" 29 | 30 | else: 31 | 32 | #userInput = raw_input("Input String: ") 33 | 34 | print "\n\n" 35 | 36 | if formatType == "1": 37 | 38 | background.paste(_1,(0,0)) 39 | background.paste(_2,(380,0)) 40 | background.show() 41 | 42 | elif formatType == "2": 43 | 44 | background.paste(_1,(380,0)) 45 | background.paste(_2,(0,0)) 46 | background.show() 47 | 48 | 49 | clipboard.set_image(background) 50 | -------------------------------------------------------------------------------- /ScreenshotsSimple.py: -------------------------------------------------------------------------------- 1 | # Based on: http://www.macstories.net/tutorials/a-better-way-to-combine-iphone-screenshots-with-keyboard-maestro/ 2 | # Uses two screenshots saved in Pythonista's image manager 3 | 4 | import Image 5 | import clipboard 6 | im1 = Image.open('_1').convert("RGB") 7 | im2 = Image.open('_3').convert("RGB") 8 | background = Image.new('RGBA', (746,650), (255, 255, 255, 255)) 9 | background.paste(im1,(0,0)) 10 | background.paste(im2,(380,0)) 11 | background.show() 12 | 13 | clipboard.set_image(background) 14 | 15 | --------------------------------------------------------------------------------