Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the '10.4: Use iCal to set a response reminder for a Mail message' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
10.4: Use iCal to set a response reminder for a Mail message
Authored by: veric on Aug 19, '05 05:53:37PM
ok, it's very far at the end of this long hint... but i've got another script which might interest some of you. i've only done a very small modification on the Mail2IcalTodo from KleinWare:
http://macupdate.com/info.php/id/10494

i've only add a little (but so usefull) reminder alarm: (and it works perfectly with the amazing and beautiful Mail'shortcutaker "Act-on" ()

with KleinWare Mail2ical (event), it's perfect...



(*

this is a little modification (set alarm with Todo item) of :

	Mail2iCalToDo, rev. 1.3.1, © 2002-2005 by Georg Klein <gklein1@mac.com>
	This script is distributed as open source software
	You are free to copy, modify and share parts of or the entire script, as long as you
	a) Keep this notice in any modified version of the script
	b) Transfer this notice to any derrivative work
	c) Don't charge money for this script or any derrivative of it
	
	This software is provided "as is" without any warranty, explicit or implied.
	The author of this software is not liable to any loss or damage of data that
	may happen by installing or using it.
*)
property pCalName : ""
property pDueDate : 72

using terms from application "Mail"
	on perform mail action with messages allMessages
		try
			set mailCal to my checkForDefault("rule")
			my generateItems(allMessages, mailCal)
		on error theError number theNumber from theOffender
			beep
			--			display alert "Error " & theNumber & " occurred" message theError as critical buttons {"OK"} default button 1 giving up after 15
		end try
	end perform mail action with messages
end using terms from

on run
	set mailCal to my checkForDefault("menu")
	tell application "Mail"
		if (count of selected messages of message viewer 1) is 0 then
			display alert "No messages selected" message "Please select some messages to export or click 'Reset' to set new defaults" buttons {"Reset", "OK"} default button 2 giving up after 15
			copy result as list to {theButton}
			if theButton is "Reset" then
				set mailCal to my chooseCalendar()
				my setDueDate()
			end if
		else
			set allMessages to selected messages of message viewer 1
			my generateItems(allMessages, mailCal)
		end if
	end tell
end run

on checkForDefault(method)
	tell application "iCal"
		try
			set mailCal to calendar pCalName
		on error errMsg number errno
			if errno is 1 then -- no calendar with this name
				if method is "rule" then -- rule execution does not allow for user interaction
					set mailCal to my createCalendar("Email") -- create calendar with default name
				else
					set mailCal to my chooseCalendar()
					my setDueDate()
				end if
			else
				error errMsg number errno
				return ""
			end if
		end try
	end tell
	return mailCal
end checkForDefault

on chooseCalendar()
	tell application "iCal"
		set allCals to title of calendars
	end tell
	set theCal to choose from list allCals with prompt "Export to which calendar" default items {pCalName} cancel button name "New" with empty selection allowed without multiple selections allowed
	if theCal is false or (count of theCal) is 0 then
		display dialog "Name your calendar" default answer "Email" buttons {"Cancel", "OK"} default button 2
		copy the result as list to {theName, theButton}
		if theButton is not "Cancel" then
			set pCalName to theName
		else
			return
		end if
		set mailCal to my createCalendar(pCalName)
	else
		set pCalName to item 1 of theCal
		tell application "iCal"
			set mailCal to calendar pCalName
		end tell
	end if
	return mailCal
end chooseCalendar

on createCalendar(calName)
	tell application "iCal"
		set mailCal to make new calendar at the end of calendars
		tell mailCal
			set title to calName
		end tell
	end tell
	return mailCal
end createCalendar

on setDueDate()
	display dialog "Set due date (in hours from arrival of mail)" default answer pDueDate buttons "Set" default button 1
	copy result as list to {theText, theButton}
	set pDueDate to theText as integer
end setDueDate

on generateItems(allMessages, mailCal)
	tell application "Mail"
		repeat with i from 1 to number of items in allMessages
			set curMessage to item i of allMessages
			set curText to reply to of curMessage & ", " & subject of curMessage
			set theHeaders to all headers of curMessage
			set hasPrio to offset of "X-Priority:" in theHeaders
			if hasPrio is not 0 then
				set xPrio to (character (hasPrio + 12) of theHeaders) as integer
				if xPrio is 1 then set calPrio to 1
				if xPrio is 2 then set calPrio to 4
				if xPrio is 3 then set calPrio to 0
				if xPrio is 4 then set calPrio to 7
				if xPrio is 5 then set calPrio to 9
			else
				set calPrio to 0
			end if
			tell application "iCal"
				set newTodo to make new todo at the end of todos of mailCal
				tell newTodo
					set summary to curText
					set due date to ((current date) + pDueDate * hours)
					set priority to calPrio
					if pDueDate is not "" then
						set theAlarm to (pDueDate as integer) * -60
						make new sound alarm at end of sound alarms of newTodo with properties {trigger interval:theAlarm}
					end if
				end tell
			end tell
		end repeat
	end tell
end generateItems



[ Reply to This | # ]