iCal - can't get summary to work properly

in my original script, everything worked great. I am able to load up an excel spreadsheet, run the script, and ical creates todo’s for every event I need. But, now I am trying to make a slight modification that keeps giving me an error.

Original code:


repeat with i from 1 to count summaryList
		set theDate to my calcDate(item i of dateList)
		set {theTodo, isCompleted} to my check_Todo(ProjectName, item i of summaryList)
		if class of theDate is date then
			if theTodo is false then
				make new todo at end of todos of calendar ProjectName with properties {due date:theDate, description:ProjectName, summary:item i of summaryList}
			else
				if isCompleted is false then set due date of theTodo to theDate
			end if
		end if
end repeat

The new code:


repeat with i from 1 to count summaryList
		set theDate to my calcDate(item i of dateList)
		set {theTodo, isCompleted} to my check_Todo(ProjectName, item i of summaryList)
		if class of theDate is date then
			if theTodo is false then
				make new todo at end of todos of calendar ProjectName with properties {due date:theDate, description:ProjectName, summary:(item i of summaryList) + ProjectName}
			else
				if isCompleted is false then set due date of theTodo to theDate
			end if
		end if
end repeat

Notice the only change is that I am trying to change the summary so that it includes the item i of summaryList, followed by the Project name. This way i can glance at the upcoming todos more quickly without needing to expand each one to see the project it belongs too.

The original code functions properly.
The new code however gives me an error saying it can’t make the item into a type number.

Any ideas?

You’ve put a plus sign instead of an ampersand. :slight_smile:

der…thanks :cool:

BUT…now I’ve realized a problem. It seems because I’m modifying the summary…its breaking my check_todo function to see if an existing todo is there and if so update the date (instead of creating a new todo). Now it is keeping the original todo, and creating a new todo at the new changed date.


property summaryList : {"Rough Ceramics", "Tooling Quote", "Casting Ceramic", "Tooling PO", "Paint Photos (MASS)", "Blister Layout", "Production Quote", "Vendor Confirmed", "Paint Master", "Decals (MASS)", "Paint Photos (CL)", "Decals (CL)", "1st Shots (New Figures)", "EP Shots (Old Figures)", "PO Breakdown", "Mockups", "EP Shots (New Figures)", "1st Deco", "PO", "Packaging Files", "Chromalins", "Blister Release", "Injection Release", "Deco Release", "Press Proofs", "Printing Release", "PP"}

tell application "Microsoft Excel"
	set ProjectName to the value of cell "$B$2"
	set range_value_List to (get value of range "E4:E37")
	set range_value to {}
	repeat with i from 1 to (count range_value_List)
		set end of range_value to item 1 of (item i of range_value_List)
	end repeat
	set {RoughCeramics, blind, ToolingQuote, CastingCeramic, blind, ToolingPO, blind, PaintPhotosMASS, BlisterLayout, ProductionQuote, VendorConfirmed, PaintMaster, DecalsMASS, DecalsCL, PaintPhotosCL, FirstShotsNew, EPShotsOld, POBreakdown, Mockups, EPShotsNew, firstDeco, PO, blind, blind, PackagingFiles, Chromalins, BlisterRelease, InjectionRelease, blind, DecoRelease, PressProofs, blind, PrintingRelease, PP} to range_value
	close front window
end tell

tell application "iCal"
	if not (exists calendar ProjectName) then
		tell (make new calendar at end of calendars with properties {name:ProjectName})
			set its color to {13500, 28500, 48500}
		end tell
	end if
	set dateList to {RoughCeramics, ToolingQuote, CastingCeramic, ToolingPO, PaintPhotosMASS, BlisterLayout, ProductionQuote, VendorConfirmed, PaintMaster, DecalsMASS, DecalsCL, PaintPhotosCL, FirstShotsNew, EPShotsOld, POBreakdown, Mockups, EPShotsNew, firstDeco, PO, PackagingFiles, Chromalins, BlisterRelease, InjectionRelease, DecoRelease, PressProofs, PrintingRelease, PP}
	repeat with i from 1 to count summaryList
		set theDate to my calcDate(item i of dateList)
		set {theTodo, isCompleted} to my check_Todo(ProjectName, (item i of summaryList) & " - " & ProjectName)
		if class of theDate is date then
			if theTodo is false then
				make new todo at end of todos of calendar ProjectName with properties {due date:theDate, description:ProjectName, summary:(item i of summaryList) & " - " & ProjectName}
			else
				if isCompleted is false then set due date of theTodo to theDate
			end if
		end if
	end repeat
end tell

on calcDate(d)
	if class of d is date then return d
	if d is "" or d is in {"N/A", "NA", "on hold"} then return false
	set delim to item (((d contains "/") as integer) + 1) of {".", "/"}
	set {TID, text item delimiters} to {text item delimiters, delim}
	try
		set {mn, dy, yr} to text items of d
		set yr to yr mod 1000 + 2000
		-- old line for above-- if yr as integer < 10 then set yr to (yr as integer) + 2000
		set text item delimiters to TID
		tell (current date) to set d to it - (its time)
		tell d to set {its day, its month, its year} to {dy as integer, mn as integer, yr as integer}
		return d
	on error
		set text item delimiters to TID
		return false
	end try
end calcDate

on check_Todo(cal, param)
	tell application "iCal"
		tell calendar cal
			repeat with tt in (get todos)
				tell contents of tt
					if summary is param then
						set c to completion date
						if c is missing value then
							return {it, false}
						else
							return {it, true}
						end if
					end if
				end tell
			end repeat
		end tell
		return {false, false}
	end tell
end check_Todo

The best approach would be to run another script first to change the summaries of your existing todos to the new convention. This should be easy, since the summary extensions are the same as the calendar names.

Otherwise, it should be enough to change ‘if summary is param then’ to ‘if summary begins with param then’ in the handler. None of the summaries in the list begins with any of the others, so there’d be no ambiguity.

thanks…worked perfectly so far.
ill update if i notice any problems.