Errands to iCal Todo

Tags ( | )

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

Version: 1

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

I fixed the code above. It

I fixed the code above. It was all typed in correctly, but it was rendered funny because for some reasons browsers are eating that "&", but not the other ones. I replaced it with the HTML equivalent code and now it displays correctly.

Problem

I'm kind of new to scripts and I was trying to get this ne working, but i get the following error message "Excpected end of line, but found identifier" relating to the word custom in the next passage "set dueDate to retrieve custom attribute errand key dueDateColumnName"
What am i doing wrong?

The script dictionary

The script dictionary changed for Mori since I posted this, introducing this error. The line should now be "set dueDate to get attribute name dueDateColumnName".

Problem

Ok, thanks for the info.

Script running -- no result in iCal

I've gotten this script running, but no result happens in iCal. Even created a folder in more called "Next Errands" and a folder in ical called "Palm". Do you have any suggestions what might be happening? As a test, I put one entry in the "next errands" folder with these attributes... Title: Test Entry, Date Due: 4/15/07, Context: Errand, GTD: act.

Thanks for your help. -John

P.S. I'm not trying this yet, but can you tell me...Will the script work with a smartfolder designated?

-----

OK. I figured out why the script was failing silently. The script works only with smartfolders. Hence, the "fetched entries" command in the script, would have needed to be "entire contents" to work (possibly) with a normal folder. I had a normal folder titled "next errands", so I delete that from my Mori document and left in the smartfolder title "next errands". Well, the script has begun to work but here's where I'm stuck now...

Using a debugger, I found that this line...

set dueDate to get attribute name dueDateColumnName

...produces the following error:

iCal got an error: Can't continue get attribute.

Appreciate any help.

For some reason AppleScript

For some reason AppleScript is looking in the wrong dictionary (since Mori's dictionary has changed to be more standard, I think iCal's get attribute is taking over Mori's). The solution should be to change the line so that it's inside of either a "tell application Mori" block or a "using terms from application Mori" block.

I looked at my code a little

I looked at my code a little closer and I see that I already had it in there like we needed. Maybe the script dictionary has changed again since I last posted that; check Mori's dictionary to make sure it still uses "get attribute name". If it doesn't, change it to whatever the terminology is now.

Barring that, I'm not really sure.

Slightly Reworked Script

I'm no Applecscript expert so this script maybe be messy...but it works, for me, most of the time. I've commented out some lines and shown where I've added. If someone can clean this up and repost, feel free. Thanks for the work a previous author did on this script, I just tweaked it a little per my marked changes to make it work on my system. Hope it helps solve some issues with the script. Also, you will see in the firsts two lines that I changed the palm calendar and folder title to match mine. Here's the script code...

property todoCal : "Info FROM Mori"
property nextErrandsEntryName : "For Treo - Alias"
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 1.6"
tell front document
set nextErrands to get entire contents 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 1.6" to tell front document to set checkbox of entry id entryID to on state
end if
set errandTodos to errandTodos end if
end if
end repeat
repeat with i from 1 to errandTodos's length
delete first item in errandTodos
end repeat
tell application "Mori 1.6" --> My addition
repeat with errand in nextErrands
using terms from application "Mori 1.6"
-->if useCustomDueDateCol then
-->set dueDate to (get attribute name dueDateColumnName) of errand
-->if dueDate is "f" then set dueDate to ""
-->else
if errand's (get attribute name "dateDue") exists then --> My addition
set dueDate to (get attribute name "dateDue") of errand --> My addition
else --> My addition
set dueDate to "" --> My addition
end if --> My addition
-->if errand's (get attribute name "dateDue") exists then
--> set errand's due date to (get attribute name "dateDue") of errand
-->else
--> set due date to ""
-->end if
-->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 note exists then
set errandNote to errand's note
else
set errandNote to ""
end if
set errandID to errand's id
end using terms from
tell application "iCal"
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 dueDate
end tell
end repeat
end tell --> My addition
if not iCalIsRunning then quit
end tell
end tell
end tell

errandTodos

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.