Groupwise Appointment to Entourage Event

If you must have Groupwise at work, but actually use Entourage as your PIM, this script will make your life easier. Any appointment forwarded out of Groupwise, to your Entourage managed account, will be made into an Entourage event. Save this into your ~/Documents/Microsoft User Data/Entourage Script Menu Items/ directory.
For extra added value, name the script with a “^E” at the end, and command e will run the script

OS version: OS X

tell application "Microsoft Entourage"
	activate
	set durationHour to "0"
	set durationMin to "0"
	set allDayEvent to false
	try
		set theMessage to displayed message of window 1
	on error
		set theMessage to current messages
	end try
	set messageContent to theMessage's content
	if messageContent begins with "From" then
		set GroupwiseAdd to true
		set AppleScript's text item delimiters to "

"
		set headerInfo to text item 1 of messageContent
		set bodyMessage to text items 2 thru end of messageContent as string
	end if
	if messageContent begins with "Item" then
		set GroupwiseAdd to false
		set headerInfo to ": " & subject of theMessage
		set bodyMessage to messageContent as string
	end if
	set AppleScript's text item delimiters to "
"
	set itemSubject to text item -1 of headerInfo
	set itemType to text item 1 of bodyMessage
	set startDate to text item 2 of bodyMessage
	set duration to text item 3 of bodyMessage
	set place to text item 4 of bodyMessage
	set AppleScript's text item delimiters to (":" & space)
	set itemSubject to text item 2 of itemSubject
	set AppleScript's text item delimiters to (":" & space & space)
	set duration to text items 2 thru end of duration as string
	set dateTemp to text item 2 of startDate
	set place to text item 2 of place
	set itemType to "Groupwise " & text item 2 of itemType
	--	wrangle duration into integers here
	set AppleScript's text item delimiters to space
	set dTimeCount to count of text items of duration
	if dTimeCount = 4 then
		set durationHour to text item 1 of duration as number
		set AppleScript's text item delimiters to "," & space
		set durationMin to text item 2 of duration as string
		set AppleScript's text item delimiters to space
		set durationMin to text item 1 of durationMin as number
		set durationMin to (durationMin / 60)
	else if dTimeCount = 2 then
		set AppleScript's text item delimiters to space
		if text item 2 of duration begins with "hour" then
			set durationHour to text item 1 of duration as number
		else if text item 2 of duration begins with "min" then
			set durationMin to text item 1 of duration as number
			set durationMin to (durationMin / 60)
		end if
	end if
	set duration to durationHour + durationMin
	set AppleScript's text item delimiters to space
	set startDate to text item 1 of dateTemp as string
	set timeTemp to text item 3 of dateTemp
	set AmPm to text item 4 of dateTemp
	set AppleScript's text item delimiters to ":"
	set timeTempHours to text item 1 of timeTemp
	set timeTempMinutes to text item 2 of timeTemp
	set timeTempMinutes to (timeTempMinutes / 60)
	if AmPm = "pm" then
		set timeTempHours to (timeTempHours + 12)
	end if
	set metricStartTime to (timeTempHours + timeTempMinutes) as string
	set metricDuration to (durationHour + durationMin) as string
	set metricEndTime to (metricStartTime + metricDuration) as string
	set AppleScript's text item delimiters to "."
	try
		set metricEndMin to text item 2 of metricEndTime
		set metricEndMin to ("." & metricEndMin) as string
		set englishEndMin to (metricEndMin * 60) as string
		set englishEndHour to text item 1 of metricEndTime
		set englishEndTime to (englishEndHour & ":" & englishEndMin)
		set englishEndTime to text item 1 of englishEndTime
	on error
		set englishEndTime to (metricEndTime & ":00")
	end try
	--check for existing appointments
	if duration > 6 then
		set allDay to display dialog "Is this an all day event?" buttons {"Yes", "No"} default button "Yes" with icon 1
		set allDayAnswer to button returned of allDay
		if allDayAnswer = "Yes" then
			set allDayEvent to true
			make new event with properties {location:place, subject:itemSubject, start time:date (startDate & " " & timeTemp), all day event:allDayEvent, content:bodyMessage}
		else
			make new event with properties {location:place, subject:itemSubject, start time:date (startDate & " " & timeTemp & AmPm), end time:date (startDate & " " & englishEndTime), content:bodyMessage}
		end if
	else
		make new event with properties {location:place, subject:itemSubject, start time:date (startDate & " " & timeTemp & AmPm), end time:date (startDate & " " & englishEndTime), content:bodyMessage}
	end if
	try
		set the read status of theMessage to untouched
	end try
end tell