Skip to content

Instantly share code, notes, and snippets.

@hiilppp hiilppp/list.py
Created Dec 10, 2013

Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

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
You can’t perform that action at this time.