Determining if an object reference exists

First of all, I am a long time PC programmer that just made the switch - Titanium G4 15" - and loving it.

I’ve been doing some personal scripting and run into a problem with this code:

set curToDo to (first todo of myCal whose uid is myUID)
if curToDo is missing value then
	set curToDo to (make todo at end of todos of myCal with properties {summary:mySummary, priority:myPriority})
end if

This is a script for iCal. What I am trying to accomplish is to find a ToDo item in a calendar with a specific UID. If that item doesn’t exist, I want to create it. The problem I am having is checking to see if setting “curToDo” actually found anything. Anytime I try to do any check on the variable “curToDo” if there was no match, I get a “variable is not defined” error. If there is a match, the remainder of my code (not listed here) runs fine. In Visual Basic and other languages, I would do something like: “if IsNull(curToDo) then …”.

What am I doing wrong here?

Thanks,

Wayne

Great! Welcome to the world of happy Mac users! :wink:

Based on a very quick test, this might work.

tell application "iCal"
	try
		set curToDo to (first todo of myCal whose uid is myUID)
	on error number -2753
		set curToDo to (make todo at end of todos of myCal with properties {summary:mySummary, priority:myPriority})
	end try
end tell