Skip to content

Instantly share code, notes, and snippets.

@derickfay
Created February 8, 2014 22:10
Show Gist options
  • Save derickfay/8891099 to your computer and use it in GitHub Desktop.
Save derickfay/8891099 to your computer and use it in GitHub Desktop.
Python script to sort text by the dates in @Due(YYYY-MM-DD) tags. Made for use with TaskPaper files.
#!/usr/bin/env python
import re
import sys
# first & only argument is the text to be parsed
theText = sys.argv[1]
theList=[]
j=""
for i in theText.splitlines():
match = re.search('@due\(\d\d\d\d\-\d\d\-\d\d\)',i)
if match:
theKey = i[i.find('@due(')+5:i.find('@due(')+15]
else:
theKey =''
theList = theList + [(theKey, i)]
for i in sorted(theList):
j = j+i[1]+"\n"
j = j[:-1]
print j
@derickfay
Copy link
Author

I run this as an OS X Service using Automator's Run Shell Script action, which makes it accessible via right-click on the selected text.

Automator

@derickfay
Copy link
Author

  • Note to self (and everyone else) - remember to set Pass Input as arguments in Automator

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