Skip to content

Instantly share code, notes, and snippets.

@hiilppp
Created December 10, 2013 01:11
Show Gist options
  • Select an option

  • Save hiilppp/7884176 to your computer and use it in GitHub Desktop.

Select an option

Save hiilppp/7884176 to your computer and use it in GitHub Desktop.
Python script to manipulate text in Pythonista in the following manner and send the result (back) to Drafts: Sort lines, remove blank and duplicate lines, and prepend a hyphen to lines which don't start with one.
# To call script from Drafts, use the follwing URL as URL Action:
# <pythonista://list.py?action=run&argv=[[draft]]>
import os
import re
import sys
import urllib
import webbrowser
a = re.sub(r"(?m)^[*-] ", "", sys.argv[1])
a = set(a.split("\n"))
a = "".join([l + "\n" for l in a])
a = os.linesep.join([s for s in a.split("\n") if s])
a = a.split("\n")
a.sort(key=str.lower)
a = "\n".join(a)
a = re.sub(r"(?m)^", "- ", a)
webbrowser.open("drafts://x-callback-url/create?text=" + urllib.quote(a))
@hiilppp
Copy link
Copy Markdown
Author

hiilppp commented Apr 22, 2014

Cf. sort.py.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment