How do I choose dates via applescript?

I’m trying to modify a script that I got somewhere (don’t remember the source) that allows me to create a quick todo in iCal. The modification that I’m trying to make is to allow me to choose a due date, (as opposed to only allowing “Today” or “Tomorrow”, which is how the script was originally written). But no matter what I do, I can’t get it to work. Here’s the script as I’ve got it now:

set iCalendars to {}
set theCals to {}
set priList to {"None", "Very Important", "Important", "Not Important"}
set priNums to {0, 3, 5, 9}

tell application "iCal"
	set theCals to calendars whose writable is true
	repeat with i from 1 to count of theCals
		copy title of item i of theCals to end of iCalendars
	end repeat
end tell

set theChoice to choose from list iCalendars with prompt "Choose the Calendar to use" OK button name "Choose" without multiple selections allowed and empty selection allowed

if theChoice is not false then
	set theCalChoice to item 1 of theChoice
end if

set theCalName to theCalChoice

set userInput to display dialog "Do what?" & return & return default answer "" buttons {"Tomorrow", "Today", "Other"} with icon note
set theSummary to text returned of userInput
if button returned of userInput is "Today" then
	set theDate to current date
else if button returned of userInput is "Tomorrow" then
	set theDate to current date
	set theDate to theDate + (24 * hours)
else if button returned of userInput is "Other" then
	set DateDialog to display dialog "Enter Date:" & return & return default answer "" with icon note
	set theDate to text returned of DateDialog as date
end if

-- Run through our Calendar list and find the iCal id of the chosen Calendar
set i to 1
repeat with anItem in iCalendars
	if item i of iCalendars is equal to theCalName then
		set theNum to i
		exit repeat
	end if
	set i to i + 1
end repeat

set currentCal to item theNum of theCals

set theChoice to choose from list priList with prompt "Choose the Priority" OK button name "Choose" without multiple selections allowed and empty selection allowed
if theChoice is not false then
	set thePriChoice to item 1 of theChoice
end if
set i to 1
repeat with anItem in priList
	if item i of priList is equal to thePriChoice then
		set theNum to i
		exit repeat
	end if
	set i to i + 1
end repeat
set thePri to item theNum of priNums

tell application "iCal"
	make todo at end of todos of currentCal with properties {due date:theDate, priority:thePri, summary:theSummary}
end tell

If I choose “Other” for due date, and then try entering any short date format (i.e. 6/18 or June 18), it gives me an error saying “Can’t make June 18 into type date” or “Can’t make 6/18 into type date.” If I omit the “as date” line from the end of the “set theDate to” line, it’s the same error, except is says “into type string”.

How do I get this to work. Or even better yet, is there something that I can do (an OSAX perhaps?) that will display a small calendar, allowing me to choose a date from that? Thanks in advance for any help.

Model: 12" PB G4 867
Browser: Safari 412
Operating System: Mac OS X (10.4)

Try this:

property userPriorities : {"None", "Very Important", "Important", "Not Important"}
using terms from application "iCal"
	property iCalPriorities : {no priority, high priority, medium priority, low priority}
end using terms from

tell application "iCal" to set iCalendars to (title of every calendar whose writable is true)
choose from list iCalendars with prompt "Choose the calendar to use:" OK button name "Choose" default items {item 1 of iCalendars}

if result is not false then
	set theCal to item 1 of result
else
	error number -128
end if

display dialog "Do what?" default answer "" buttons {"Other", "Today", "Tomorrow"} default button 3 with icon note
copy result to {text returned:theSummary, button returned:result}

if button returned of result is "Today" then
	set theDate to (current date)
else if button returned of result is "Tomorrow" then
	set theDate to ((current date) + (1 * days))
else
	repeat
		display dialog "Which date?" default answer "" with icon note
		try
			set theDate to date (text returned of result)
			exit repeat
		on error errorMsg
			display dialog errorMsg
		end try
	end repeat
end if

choose from list userPriorities with prompt "Choose the priority:" OK button name "Choose" default items {item 1 of userPriorities}
if result is not false then
	set thePriority to item 1 of result
	repeat with i from 1 to 4
		if thePriority is equal to (item i of userPriorities) then set thePriority to (item i of iCalPriorities)
	end repeat
else
	error number -128
end if

tell application "iCal" to make new todo at end of todos of calendar theCal with properties {due date:theDate, priority:thePriority, summary:theSummary}

BTW, you no longer need Convert Script to Markup Code, because this forum now has native formatting/highlighting. Just put your code inside an applescript tag (the same way you use other BBCode tags).

Model: Mac mini
AppleScript: 1.10
Browser: Safari 412
Operating System: Mac OS X (10.4)

I see two problems: First that there is no default answer, and second, the way you’re forming the date. Should look like this:

set DateDialog to display dialog "Enter date as month and day" with icon note default answer ""
set theDate to date (text returned of DateDialog)

Thanks, guys, both methods worked like a champ (I like to use 6/18 as the input date format, and both of your methods worked great). I just don’t know which one is better, but I guess it doesn’t matter, now that it works!
guardian34–I didn’t know that the BBS automatically formats scripts, so thanks for the tip! However, I still like the look of “Convert Script to Markup Code,” especially since it still color codes it. I’m still a newbie to AS, and a very visually oriented person, so for me, the color coding better helps me to see and recognize variables, classes, actions, commands, etc.
NovaScotian–I did have a default answer to the dialog–look again. Perhaps my syntax for it was off, or it was in the wrong place, but it’s there.
Anyways, thanks again so much for the help. It’s all these little things that makes Macs so great!
FWIW, I’ve set this script up as a Quicksilver trigger, so adding ToDo’s (which I do frequently) is now just a few keys away no matter what I’m doing.