Skip to content

Instantly share code, notes, and snippets.

@ejetzer
Created January 23, 2016 17:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ejetzer/12a932cace06d20b0c3a to your computer and use it in GitHub Desktop.
Save ejetzer/12a932cace06d20b0c3a to your computer and use it in GitHub Desktop.
Compile Tasks.py
# coding: utf-8
import appex, dialogs, scene
import plistlib, copy, webbrowser, urllib, time
# check out http://handleopenurl.com/
db = 'Tasks.txt'
url = 'omnifocus://task/%s'
due = 'due://x-callback-url/add?title=%s&hourslater=4&x-success=pythonista://&x-error=pythonista://&x-source=Pythonista'
def get_tasks(shared):
# [{'attachments': [{'com.omnigroup.omnifocus.ofaction': None, 'public.file-url': None}]}]
tasks = shared[0]['attachments']
tasks = (t['public.file-url'] for t in tasks)
tasks = (open(n).read() for n in tasks)
tasks = (plistlib.readPlistFromString(t) for t in tasks)
# {'newActions': [{'name': 'None', 'uuid': 'None'}]}
tasks = (t['newActions'][0] for t in tasks)
tasks = ((t['name'], url % t['uuid']) for t in tasks)
tasks = (' '.join(t) + '\n' for t in tasks)
return tasks
def main():
if not appex.is_running_extension():
with open(db) as tasks:
for task in tasks:
task = urllib.quote(task)
webbrowser.open(due % task)
time.sleep(10)
open(db, 'w').close() # Erase file
else:
shared = appex.get_input()
if shared: tasks = get_tasks(shared)
with open(db, 'a') as dbfile:
dbfile.writelines(tasks)
#for task in tasks:
#dialogs.share_text(task)
dialogs.alert('Done!', '', 'Ok', hide_cancel_button=True)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment