CommandLineNewTodo

Overview

A extension of this script using this technique. This script reads new todos with an optional note from the command line and adds them to your inbox.

Note: if you get an error on 10.6

osascript[4956:903] Error loading /Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types: dlopen(/Library/ScriptingAdditions/Adobe Unit Types.osax/Contents/MacOS/Adobe Unit Types, 262): no suitable image found.

try replacing '/usr/bin/osascript'

with 'arch -i386 /usr/bin/osascript'

as documented in

http://kb2.adobe.com/cps/516/cpsid_51615.html

The problem is caused by 32/64 bit mismatch in libraries.

Usage

# ./todo.sh
first todo
second todo<tab>a note
third todo
^d

ls | todo.sh

Code

#!/bin/sh
# 
#  Applescript adapted from: http://culturedcode.com/things/wiki/index.php/Importing_name_and_note_to-dos_from_a_file_%28AppleScript%29
#
#  Stdin idea taken from: http://appliedabstraction.blogspot.com/2008/04/applescript-shell-and-stdin.html

STANDIN=$(mktemp /tmp/seereport.XXXXXXXXXXXX) || exit 1
cat > $STANDIN

/usr/bin/osascript > /dev/null <<ASCPT
set database_text to do shell script "cat $STANDIN"
	repeat with i from 1 to (count paragraphs of database_text)
		set the_database_record to paragraph i of database_text
		set text item delimiters to tab
		set field_list to every text item of the_database_record
		set todoName to item 1 of field_list
		set todoNotes to ""
		try
			set todoNotes to item 2 of field_list
		end try
		if todoNotes is ""
			tell application "Things"
				set newToDo to make new to do ¬
					with properties {name:todoName} ¬
					at beginning of list "Inbox"
			end tell
		else
			tell application "Things"
				set newToDo to make new to do ¬
					with properties {name:todoName, notes:todoNotes} ¬
					at beginning of list "Inbox"
			end tell
		end if
	end repeat
ASCPT

trap 'rm -f $STANDIN' EXIT