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: zmagyar on Jul 16, '05 05:30:08PM
OK, here is the corrected version, for Finder to open the file I had to replace the / with :, sure, why make the life easy....
Whatever, here it is. For the todo functionality, please, just drag the event to the todo list and you are done, but if you really really want to have it, let me know...

--NOTE: the events will be created in the callender named "MailFollowup".
--it is hardcoded, if you don't like it, change it in the code ;-)
--for insturctions see Script Description

display dialog "Please Choose:" buttons {"Create Event", "Get ID", "Open Mail with ID"} default button 2 with icon 1
if button returned of result = "Create Event" then
	my Create_Event()
else if button returned of result = "Get ID" then
	my Get_ID()
else if button returned of result = "Open Mail with ID" then
	my Open_Mail_with_ID2()
else
	display dialog "Something went wrong"
end if

on Create_Event()
	set messInfo to (my Get_Mess_Info2())
	set messInfo to messInfo as list
	set messSubject to item 1 of messInfo
	set mailMessID to item 2 of messInfo
	
	tell application "iCal"
		activate
		set theCal to 0
		set callist to {}
		--repeat with i in (calendars whose writable is true)
		repeat with i in calendars
			set caltitle to title of i
			set callist to callist & caltitle --(title of i)
		end repeat
	end tell
	
	--set thecal to item 1 of (choose from list callist)
	set theCal to "MailFollowup"
	repeat with i from 1 to (count callist)
		if theCal = item i of callist then
			exit repeat
		end if
	end repeat
	set theCal to i
	
	tell application "iCal"
		calendar theCal exists
	end tell
	
	tell application "iCal"
		--	make new event at the end of events of calendar thecal with properties {start date:startdate, end date:enddate, summary:thetitle, description:descript}
		set newEvent to (make new event at the end of events of calendar theCal with properties {start date:(current date), end date:(current date), summary:messSubject, description:"Message ID: " & mailMessID})
		show newEvent
		--current date
	end tell
end Create_Event

on Get_ID()
	set messInfo to (my Get_Mess_Info2())
	set messSubject to item 1 of messInfo
	set mailMessID to item 2 of messInfo
	set the clipboard to "MMID " & mailMessID
	
	tell application "iCal"
		activate
	end tell
end Get_ID

on Open_Mail_with_ID2()
	tell application "Mail"
		activate
		set slectedMessmyMessIDs to (askPassword "Enter Message ID")
		--this is the part where we search for the email message file
		--the search is slow and CPU intensive, it has to run better
		--set the_search to do shell script "mdfind \"kMDItemKind == 'emlx' \"| grep -iw " & slectedMessmyMessIDs & ".emlx" & " | grep -v grep "
		
		set slectedMessmyMessIDs to slectedMessmyMessIDs & ".emlx" as string
		--log slectedMessmyMessIDs
		--log "mdfind \"kMDItemFSName = " & slectedMessmyMessIDs & "\" | grep /" & slectedMessmyMessIDs
		set the_search to do shell script "mdfind \"kMDItemFSName = " & slectedMessmyMessIDs & "\" | grep /" & slectedMessmyMessIDs
		
		--here we should figure out how to open the found message file
		--as at the moment I don't know how, I simply display the path and file name
		--this shows if the code is working fine and you might even want to manually
		--navigate to this path and open it by doubleclicking
		--of course this is more then akward
		set the_search to the_search as string
		--display dialog the_search
		set converted_path to my findAndReplace("/", ":", the_search)
		tell application "Finder"
			set bootvol to displayed name of startup disk
			set fullpath to bootvol & converted_path
			open file fullpath
		end tell
	end tell
end Open_Mail_with_ID2

------------------------------------------------------------------------------------------------

on Get_Mess_Info2()
	tell application "Mail"
		activate
		--set messageSelection to selected messages of message viewer 1
		--the line above is OK if you have only one message viewer open, but if you have
		--two or more then we have to find the front one...
		set mywin to window of the message viewers
		set mymsgviewers to message viewers
		set winindex to index of item 1 of mywin
		if winindex is equal to 1 then
			set frontmsgview to item 1 of mymsgviewers
		else
			set frontmsgview to item 2 of mymsgviewers
		end if
		set messageSelection to selected messages of frontmsgview
		if (count of messageSelection) is equal to 0 then
			display dialog "Please select a message in Mail first, then run this script again."
		else if (count of messageSelection) is equal to 1 then
			--geting the reference to the selected message
			set selectedMessage to item 1 of messageSelection
			set messSubject to subject of selectedMessage
			if messSubject is equal to "" then
				display dialog "Mail subject equals empty string! continuting..."
			end if
			set mailMessID to id of selectedMessage
			if mailMessID is equal to 0 then
				display dialog "Mail ID equals 0, something went wrong, exiting..."
				exit repeat
			end if
			return {messSubject, mailMessID}
		else
			display dialog "Please select only one message in Mail first, then run this script again."
		end if
	end tell
	return
end Get_Mess_Info2

on findAndReplace(tofind, toreplace, TheString)
	set ditd to text item delimiters
	set res to missing value
	set text item delimiters to tofind
	repeat with tis in text items of TheString
		if res is missing value then
			set res to tis
		else
			set res to res & toreplace & tis
		end if
	end repeat
	set text item delimiters to ditd
	return res
end findAndReplace

Let me know how does it work.
Zsolt

[ Reply to This | # ]
10.4: Use iCal to set a response reminder for a Mail message
Authored by: BOlle on Jul 16, '05 06:13:09PM

I feel like a freaking noob, but i can't seem to save the code in Scriptmaker.

It complains: Expected ", " but found ".
The . is part of the error message. I've translated the error, i'm on a Dutch OS X (10.3.9). Any suggestions?



[ Reply to This | # ]
10.4: Use iCal to set a response reminder for a Mail message
Authored by: BOlle on Jul 17, '05 05:44:21AM

Forgot to mention that Scriptmaker jumps to this line:

set slectedMessmyMessIDs to (askPassword "Enter Message ID")

and selects the first "



[ Reply to This | # ]
10.4: Use iCal to set a response reminder for a Mail message
Authored by: zmagyar on Jul 20, '05 03:40:18AM

To make the life easyer, post your email address and I will send you the script
Zsolt



[ Reply to This | # ]
10.4: Use iCal to set a response reminder for a Mail message
Authored by: BOlle on Jul 20, '05 04:44:46AM

Tnx: osxhints at xs4all dot nl



[ Reply to This | # ]
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 | # ]