iCal and Applescript

Hi guys! I’m trying to make a script to run on the first of every month (through cron) to create To Do’s. But I’m having trouble passing a date to iCal. Any help would be appreciated!

Here is the code so far…



-- doesn't create duplicates. adds todo's to calendar "Personal"
on createTodo(summaryText)
	set now to current date
	set midnight to now - (time of now)
	tell application "iCal"
		-- don't create an item if it already exists for today!
		if (count (every todo in calendar ¬
			"Bills" whose due date ≥ midnight ¬
			and summary = summaryText)) < 1 then
			make new todo ¬
				at end of calendar ¬
				"Bills" with properties ¬
				({due date:now, summary:summaryText})
		end if
	end tell
end createTodo

createTodo("Pay Rent")


Hi and welcome.

The syntax to create a new todo is

make new todo at end of todos of calendar "calendar"

Because the reference to the calendar is needed twice, a tell block is used

on createTodo(summaryText)
    set now to current date
    set midnight to now - (time of now)
    tell application "iCal"
        -- don't create an item if it already exists for today!
        tell calendar "Bills"
            if (count (every todo whose due date ≥ midnight and summary = summaryText)) < 1 then
                make new todo at end of todos with properties ({due date:now, summary:summaryText})
            end if
        end tell
    end tell
end createTodo

createTodo("Pay Rent")

Interestingly, the original script posted worked for me as it was, with or without a future todo.