Created
August 10, 2012 00:13
-
-
Save parezcoydigo/3309400 to your computer and use it in GitHub Desktop.
Add task to The Hit List from the Terminal
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
#! usr/bin/env python | |
# -*- encoding: utf8 -*- | |
# Requires Python 2.7, or 2.6 with argparse installed. | |
# Currently adds task to The Hit List only to the inbox. | |
import argparse, os | |
def add(params) | |
# construct the property list for the task | |
props = '{ created date: now, ' | |
try: | |
props += 'due date: date "'+params.pop('date')+'", ' | |
except: | |
pass | |
try: | |
props += 'notes: "'+params.pop('note')+'", ' | |
except: | |
pass | |
# build the task itself, with context and tags | |
task = params.pop('title') | |
try: | |
for tag in tags: | |
task += " "+tags[tag] | |
params.pop('tags') | |
except: | |
pass | |
try: | |
for item in params: | |
task += " "+params[item] | |
except: | |
pass | |
props += 'title: "'+task+'" }' | |
# construct applescript to add task | |
task_add = '''tell application "The Hit List" | |
set now to current date | |
tell inbox to make new task with properties %s | |
end tell''' % (props) | |
#pass applescript to osascript | |
osa_call = "osascript -e '"+task_add+"'" | |
os.system(osa_call) | |
functions = {'add':add } | |
p = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter, description=''' | |
Add a task to The Hit List inbox: | |
python newtask.py add "<title of task>" -d="m/d/yy hh:mm pm|am" -n="<text of note>" | |
Due dates can be either just a date, or a date + time, as long as am or pm is included. | |
Options: | |
-t, --tags </tag> | |
-c, --context <@context> | |
-n, --note <task note> | |
-d, --due <due date> | |
''' | |
p.add_argument("cmd", help=argparse.SUPPRESS, nargs="*") | |
p.add_argument("-d","--date") | |
p.add_argument("-c","--context") | |
p.add_argument("-n","--note") | |
p.add_argument("-t","--tags", nargs="*") | |
opts = avrs(p.parse_args()) | |
cmd = opts.pop('cmd') | |
params = { k : opts[k] for k in opts if opts[k] != None } | |
params['title'] = cmd.pop(1) | |
functions[cmd[0]](params) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Currently only supports adding task to the inbox. But, it's written to easily add new functions to do other things, including listing tasks by project or list, canceling tasks, starting or stopping timer, etc.