importsys,re,clipboard,json,webbrowserfromurllibimportparsedefmain(encoded):""" Extracts task name, note and due date from an OmniFocus task URL and returns a dictionary. """task_name=Nonetask_note=Nonedue_date=None# Patterns to match the task name and the# task note in the OmniFocus URL.# The URL will look this:# omnifocus:///task/cahy7K5409b?name=Task%20name¶llel=true&due=2017-05-19%2017:00&project=My%20Projectname_pattern=re.compile(r'name=([^&]+)&')note_pattern=re.compile(r'note=([^&]+)&')due_date_pattern=re.compile(r'due=([^&]+)&')# Get the task name from the URL and# replace URL-encoded characters# (e.g., replace %20 with a space)name_match=name_pattern.search(encoded)ifname_matchisnotNone:task_name=parse.unquote(name_match.groups()[0])# Get the task note (if present) from the URL and# replace URL-encoded charactersnote_match=note_pattern.search(encoded)ifnote_matchisnotNone:task_note=parse.unquote(note_match.groups()[0])# Get the due date (if present) from the URL and# replace URL-encoded charactersdue_date_match=due_date_pattern.search(encoded)ifdue_date_matchisnotNone:due_date=parse.unquote(due_date_match.groups()[0])# Create a dictionary with the task name,# task note (if present) and due date (if present).task_info={'name':task_name}iftask_noteisnotNone:task_info['note']=task_noteelse:task_info['note']='(None)'ifdue_dateisnotNone:task_info['due_date']=due_dateelse:task_info['due_date']='(None)'# Write the dictionary to a JSON string# and copy the string to the clipboard.task_info_json=json.dumps(task_info)clipboard.set(task_info_json)# Finally, open OmniFocus to continue running the workflowwebbrowser.open('omnifocus://')if__name__=="__main__":main(sys.argv[1])
Comments (0)
HTTPSSSH
You can clone a snippet to your computer for local editing.
Learn more.