Skip to content

Instantly share code, notes, and snippets.

@derickfay derickfay/tpsort.py
Created Feb 8, 2014

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

This comment has been minimized.

Copy link
Owner Author

commented Feb 8, 2014

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

This comment has been minimized.

Copy link
Owner Author

commented Jan 23, 2015

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