Created
January 23, 2016 17:35
-
-
Save ejetzer/2664672b8ca158c5533c to your computer and use it in GitHub Desktop.
Compile Tasks.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
import appex, dialogs, console | |
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) | |
while console.is_in_background(): | |
time.sleep(1) | |
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