Adding an IF statement?

Im trying to update some old scripts I had for work and combine them possibly.

Below are 2 scripts (Script 1 and Script 2).
They are almost identical, with the exception of a few adjustments to the summary list and range_value.
This is because Script 1 follows an old excel template, and Script 2 follows a newer updated excel template.

When Entourage sees the attachement as an excel file, it auto saves into a folder on my computer.
In the past, I only had Script 1, so it was set to run on all items as they are added to the folder. It would open each file and cipy the data needed into iCal calendar todos so that I can keep track of things better.

Now that I have 2 scripts needed to run, I need to do the following:
a - I need to add a test in the begining, before the scripts are run, so that :

If the value of cell “$E$12” is “Ceramics”, then run Script 1.
If not, then run Script 2.

b - I need to edit the scripts so that they only run when called, instead of on each item added to the folder. Only the test in the begining should be run to each item added to folder.

c - I need to make sure that when many items are added to a folder, it will run the correct script for each file. Some files may be old and need Script 1. Some files may be new and need Script 2.

Any helps would be greatly appreciated.

Script 1:


property summaryList : {"Tooling PO", "Paintmaster", "Vendor", "1st Shots", "Layout", "1st Deco", "Mock-up", "Packaging", "TRI", "EP", "PO", "PP"}

on adding folder items to this_folder after receiving added_items
	-- set added_items to (choose file) as list
	repeat with anitem in added_items
		tell application "Microsoft Excel"
			open anitem
			set ProjectName to the value of cell "$F$4"
			set ReviseDate to the value of cell "$Z$4"
			set range_value to item 1 of (get value of range "K12:U12")
			set {ToolDate, PaintDate, blind, VendorDate, FirstShot, Blister, firstDeco, Mockup, Artwork, EP, PODate} to range_value
			set PPDate to the value of cell "$Y$12"
			copy Artwork to TRI
			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, description:ReviseDate as text})
					set its color to {37500, 0, 0}
				end tell
			end if
			set dateList to {ToolDate, PaintDate, VendorDate, FirstShot, Blister, firstDeco, Mockup, Artwork, TRI, EP, PODate, PPDate}
			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 item i of summaryList is "TRI" then set theDate to theDate + weeks
					if theTodo is false or (item i of summaryList is "TRI" and isCompleted is false) then
						if item i of summaryList is "TRI" and theTodo is not false then delete theTodo
						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
		end tell
	end repeat
	quit application "iCal"
end adding folder items to

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
		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
						try
							c
							return {it, true}
						on error
							return {it, false}
						end try
					end if
				end tell
			end repeat
		end tell
		return {false, false}
	end tell
end check_Todo

Script 2:


property summaryList : {"Tooling PO", "Paint Photos", "Layout", "Vendor", "PaintMasters", "1st Shot", "Mock-up", "Packaging", "TRI", "EP", "1st Deco", "PO", "PP"}

on adding folder items to this_folder after receiving added_items
	-- set added_items to (choose file) as list
	repeat with anitem in added_items
		tell application "Microsoft Excel"
			open anitem
			set ProjectName to the value of cell "$F$4"
			set ReviseDate to the value of cell "$Z$4"
			set range_value to item 1 of (get value of range "J12:U12")
			set {ToolDate, PaintPhotos, Blister, blind, VendorDate, PaintMaster, FirstShot, Mockup, Artwork, EP, firstDeco, PODate} to range_value
			set PPDate to the value of cell "$Y$12"
			copy Artwork to TRI
			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, description:ReviseDate as text})
					set its color to {37500, 0, 0}
				end tell
			end if
			set dateList to {ToolDate, PaintPhotos, Blister, blind, VendorDate, PaintMaster, FirstShot, Mockup, Artwork, EP, firstDeco, PODate, PPDate}
			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 item i of summaryList is "TRI" then set theDate to theDate + weeks
					if theTodo is false or (item i of summaryList is "TRI" and isCompleted is false) then
						if item i of summaryList is "TRI" and theTodo is not false then delete theTodo
						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
		end tell
	end repeat
	quit application "iCal"
end adding folder items to

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
		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
						try
							c
							return {it, true}
						on error
							return {it, false}
						end try
					end if
				end tell
			end repeat
		end tell
		return {false, false}
	end tell
end check_Todo

Hi,

I merged both scripts (I hope I found all differences)
the “versioncheck” will be performed for each Excel file


property summaryList1 : {"Tooling PO", "Paintmaster", "Vendor", "1st Shots", "Layout", "1st Deco", "Mock-up", "Packaging", "TRI", "EP", "PO", "PP"}
property summaryList2 : {"Tooling PO", "Paint Photos", "Layout", "Vendor", "PaintMasters", "1st Shot", "Mock-up", "Packaging", "TRI", "EP", "1st Deco", "PO", "PP"}

on adding folder items to this_folder after receiving added_items
	-- set added_items to (choose file) as list
	repeat with anitem in added_items
		tell application "Microsoft Excel"
			open anitem
			set oldVersion to (value of cell "$E$12" is "Ceramics") -- make version check
			set ProjectName to the value of cell "$F$4"
			set ReviseDate to the value of cell "$Z$4"
			if oldVersion then
				set range_value to item 1 of (get value of range "K12:U12")
				set {ToolDate, PaintDate, blind, VendorDate, FirstShot, Blister, firstDeco, Mockup, Artwork, EP, PODate} to range_value
			else
				set range_value to item 1 of (get value of range "J12:U12")
				set {ToolDate, PaintPhotos, Blister, blind, VendorDate, PaintMaster, FirstShot, Mockup, Artwork, EP, firstDeco, PODate} to range_value
			end if
			set PPDate to the value of cell "$Y$12"
			copy Artwork to TRI
			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, description:ReviseDate as text})
					set its color to {37500, 0, 0}
				end tell
			end if
			if oldVersion then
				set dateList to {ToolDate, PaintDate, VendorDate, FirstShot, Blister, firstDeco, Mockup, Artwork, TRI, EP, PODate, PPDate}
				copy summaryList1 to summaryList
			else
				set dateList to {ToolDate, PaintPhotos, Blister, blind, VendorDate, PaintMaster, FirstShot, Mockup, Artwork, EP, firstDeco, PODate, PPDate}
				copy summaryList2 to summaryList
			end if
			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 item i of summaryList is "TRI" then set theDate to theDate + weeks
					if theTodo is false or (item i of summaryList is "TRI" and isCompleted is false) then
						if item i of summaryList is "TRI" and theTodo is not false then delete theTodo
						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
		end tell
	end repeat
	quit application "iCal"
end adding folder items to

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
		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
						try
							c
							return {it, true}
						on error
							return {it, false}
						end try
					end if
				end tell
			end repeat
		end tell
		return {false, false}
	end tell
end check_Todo