This script will take errands (listed as entries) from a Mori notebook in a specified errand's folder and turn them into iCal Todo items that you can take with you on your phone. The script is named for my use of it, to put errand actions in my mGTD notebook into iCal so I can sync them to my phone and have that list with me when I'm out. It will also mark entries in Mori as completed if they were checked off in iCal.
You can set which column is used for the due date: the default due date column or a custom text column. You must also specify a calendar into which to insert the todos; I use my "Palm" calendar but you must choose a valid calendar name in your iCal or the script will fail.
property todoCal : "Palm"
property nextErrandsEntryName : "Next Errands"
property useCustomDueDateCol : true
property dueDateColumnName : "dateDue"
global iCalIsRunning
global errandTodos
tell application "System Events"
set myList to application processes
set liststring to " "
repeat with anApp in myList
set liststring to liststring & anApp's name & " "
end repeat
set iCalIsRunning to liststring contains " iCal "
end tell
tell application "Mori"
tell front document
set nextErrands to fetched entries of entry nextErrandsEntryName
tell application "iCal"
set oldTodos to every todo of calendar todoCal
set errandTodos to {}
repeat with aTodo in oldTodos
if aTodo's url exists then
if aTodo's url contains "mori" then
if aTodo's completion date exists then
set aTodosURL to aTodo's url as string
set AppleScript's text item delimiters to {":"}
set aTodosURLList to aTodosURL's text items
set AppleScript's text item delimiters to {""} --> restore delimiters to default value
set entryID to aTodosURLList's second item as number
tell application "Mori" to tell front document to set checkbox of entry id entryID to on state
end if
set errandTodos to errandTodos & {aTodo}
end if
end if
end repeat
repeat with i from 1 to errandTodos's length
delete first item in errandTodos
end repeat
repeat with errand in nextErrands
using terms from application "Mori"
if useCustomDueDateCol then
set dueDate to retrieve custom attribute errand key dueDateColumnName
if dueDate is "f" then set dueDate to ""
else
if errand's due date exists then
set dueDate to errand's due date
else
set dueDate to ""
end if
end if
set errandName to errand's name
if errand's comment exists then
set errandNote to errand's comment
else
set errandNote to ""
end if
set errandID to errand's id
end using terms from
make new todo at end of todos of calendar todoCal with properties {summary:errandName, description:errandNote, url:"mori:" & errandID}
if dueDate is not "" then set result's due date to date dueDate
end repeat
if not iCalIsRunning then quit
end tell
end tell
end tell
errandTodos
Hello! unfortunately when
Hello!
unfortunately when trying to translate the script in script editor I get an error "expect a when" instead of if at:
set errandTodos to errandTodos end if