Script not accepting parameter

Using a variable for the date/time string does not work. Using a quoted string does work. For example this does not work:

on run {theCal, eventName}
	tell application "iCal"
		tell calendar theCal
			set theDate to "Friday 16 May 2008 16:00:00"
			make new event at end of events with properties {summary:eventName, start date:date theDate}
		end tell
	end tell
end run

But this DOES work:

on run {theCal, eventName}
	tell application "iCal"
		tell calendar theCal
			--set theDate to "Friday 16 May 2008 16:00:00"
			make new event at end of events with properties {summary:eventName, start date:date "Friday 16 May 2008 16:00:00"}
		end tell
	end tell
end run

The problem is that I want to pass the date/time property as a parameter along with theCal and eventName.

It’s late (for me) and I shouldn’t bother to venture this, but…

Try this instead…

Peter B.



on run {theCal, eventName}
   tell application "iCal"
       tell calendar theCal
           set theDate to "Friday 16 May 2008 16:00:00"
           make new event at end of events with properties {summary:eventName, start date:theDate}
       end tell
   end tell
end run

Unfortunately, that didn’t work. I can’t find the difference between your script and the one I posted (the script at the beginning of my post that is an example of what doesn’t work). Am I missing something?

A date specified with a literal string depends always on international date format settings
and must match exactly one of the given formats.

set theDate to "Friday 16 May 2008 16:00:00"
date theDate

works fine with US and GB formats, but for example throws an error on a french system.

The problem in this case seems to be that iCal doesn’t like realising the date on the fly. In the version of tfindlay9’s script that does work, the date object is compiled into the script. In the version that doesn’t, it’s realised at run time from the specifier date + variable within the iCal calendar tell block. If the date’s realised before the tell block, the script works:

on run {thecal, eventName, dateText}
	set dateText to "Friday 16 May 2008 16:00:00" -- Obviously this will be passed as a parameter in the final script.
	set theDate to date dateText
	tell application "iCal"
		tell calendar thecal
			make new event at end of events with properties {summary:eventName, start date:theDate}
		end tell
	end tell
end run

Thank you!!! I would never have figured that out on my own.