Newbie can't seem to pass variables...

Am trying to get OS X stuff to work with Novell GroupWise. This script would like to parse the first few lines of an email, extract appointment info, and create an entry in iCal.

The variables I’m trying to pass are descp, a concatenated string, and onlyDate, a date. For the life of me, I can figure out why the variables in the parsing routine don’t pass to the iCal routine. Any help would be greatly appreciated!


global apType
global duration
global place
global onlyDate

using terms from application "Mail"
	on perform mail action with messages theSelectedMessages
		tell application "Mail"
			repeat with eachMessage in theSelectedMessages
				(*set theSender to extract name from sender of eachMessage
				display dialog "name:" & theSender
				set theAddress to extract address from sender of eachMessage
				display dialog "address:" & theAddress*)
				set theBody to content of eachMessage
				--display dialog theBody
				
				set AppleScript's text item delimiters to {": "}
				
				set theType to paragraph 1 of theBody
				set strDelim to every text item of theType
				set apType to item 2 of strDelim
				--display dialog apType
				
				set theType to paragraph 3 of theBody
				set strDelim to every text item of theType
				set duration to item 2 of strDelim
				--display dialog duration
				
				set theType to paragraph 4 of theBody
				set strDelim to every text item of theType
				set place to item 2 of strDelim
				--display dialog place
				
				display dialog "Type: " & apType
				display dialog "Duration: " & duration
				display dialog "Place: " & place
				set descp to (apType & " " & duration & " Location: " & place) as string
				display dialog descp
				
				set theType to paragraph 2 of theBody
				set strDelim to every text item of theType
				set startDate to item 2 of strDelim
				set AppleScript's text item delimiters to {" ("}
				set dateParts to every text item of startDate
				set thisDate to item 1 of dateParts
				if thisDate ends with "pm" then
					set AppleScript's text item delimiters to {"pm"}
					set ext to " PM"
				else
					set AppleScript's text item delimiters to {"am"}
					set ext to " AM"
				end if
				set dateDelim to every text item of thisDate
				global onlyDate
				set onlyDate to date (item 1 of dateDelim) & ext
				--return true
				
			end repeat
		end tell
		
	end perform mail action with messages
	
	tell application "iCal"
		activate
		set paracal to (first calendar whose title is "Paramount")
		make new event at end of events of paracal with properties ¬
			{summary:descp, start date:onlyDate, end date:onlyDate}
		set new_event to result
		tell new_event
			make new display alarm at end of display alarms with properties ¬
				{trigger interval:0}
		end tell
	end tell
end using terms from

When Mail calls your script, it is only executed the handler “perform mail action” (the stuff between “perform” and “end perform”). Simply move your iCal code into this handler.
Actually, such part is inside an implicit “run” handler. You can declare a run handler or not, but it’s the same:

on run
     beep
end run

Is equal to:

beep

Thanks much!

Now I just need to figure out how I broke the date routine!

Brian