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

Link iCal events and to-dos to to any Mail message Apps
If you want to link any event or to do in your iCal calendar to a specific email in Mail (without using MailTags), then here's how:
  1. Paste this text into Script Editor (or download the script) and save it to some directory (like your user's Library/Scripts folder, if you're using the script menu).
  2. Select the email you want to link, and run the script.
  3. After the beep, hit paste in the URL field of an event or To Do.
You can now open the linked email by clicking on the URL field in the inspector, and selecting Go to Location.
    •    
  • Currently 2.50 / 5
  • 1
  • 2
  • 3
  • 4
  • 5
  (2 votes cast)
 
[12,882 views]  

Link iCal events and to-dos to to any Mail message | 14 comments | Create New Account
Click here to return to the 'Link iCal events and to-dos to to any Mail message' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Thanks but I'll stick with MailTags..
Authored by: alexmathew on Nov 15, '06 08:30:59AM

There are too many scripts and hotkeys floating around on my Mac already - that I cannot keep track of them anymore. Why bother when MailTags does this job very nicely - though I do see the usefulness of this hint for someone trying to automate tasks.
AM



[ Reply to This | # ]
Link iCal events and to-dos to to any Mail message
Authored by: jdo017 on Nov 15, '06 08:41:40AM

I think this is a very useful hint. I have MailTags installed but use if very rarely if it all. This allows you to copy the URL into an event or a to-do. If I am not mistaken MailTags only does to-dos. Great work!

---
God invented the integers, all else is the work of man.



[ Reply to This | # ]
Move To-Do's to Events and back by this hint...
Authored by: alexmathew on Nov 15, '06 09:38:45AM
Link iCal events and to-dos to to any Mail message
Authored by: macorama on Nov 15, '06 08:50:28AM

Thank you so much! I searched for a script like yours for so long (I am not the best in Applescript) because I wanted an easy way to link to a specific mail from some other apps like Omnioutliner, textedit etc.

THANK YOU!



[ Reply to This | # ]
Link iCal events and to-dos to to any Mail message
Authored by: Nasir on Nov 15, '06 09:33:58AM
The script has one big advantage: the link will stop working when the mail is moved to a different mailbox, as it points to a specific file in the filesystem.

Two weeks ago, I released an application called "LinkABoo" which basically offers the same functionality, but is able to handle moved mails.
The website is: http://www.bluem.net/downloads/linkaboo-en/

At the moment, it only works with POP3 accounts, but within the next few days a version capable of handling IMAP mails will be released.

[ Reply to This | # ]
Link iCal events and to-dos to to any Mail message
Authored by: Mike A on Nov 15, '06 09:37:29AM

I ought to point out that this only works as long as the e-mail file remains in the same place. If you move a message from one mailbox to another, at some point the original file that this URL points to will be deleted.



[ Reply to This | # ]
Link iCal events and to-dos to to any Mail message
Authored by: smorr on Nov 15, '06 10:27:20AM
Just to echo and reply to a couple of comments:
  1. link will only be valid until message moves.
  2. MailTags 2.0 (in beta) now uses a message:// url scheme to link to the message (prior to this, MT would update ical if the message was moved)
  3. I am going to be releasing another beta (very soon) that implements events in MailTags.


[ Reply to This | # ]
Link iCal events and to-dos to to any Mail message
Authored by: FlyBoy on Nov 15, '06 12:13:22PM
Hi,

I wrote a little applescript that uses the message://messageId URL scheme. The script gets the message ID, escapes characters not allowed in a URL using a ruby script, and places the message URL on the clipboard. It can be adapted fairly easily to add the URL into an iCal event. I put it on the clipboard so that I put the URL anywhere I want it.

Here's the applescript:


set theID to ""
tell application "Mail"
tell front message viewer

set theSelMess to selected messages
if (count of theSelMess) is greater than 1 then
display dialog "Only select one message"
return
end if
tell item 1 of theSelMess
set theID to message id
end tell

end tell
set the clipboard to theID
do shell script "/Users/nacohen/bin/messID2messURL.rb"
set theclip to the clipboard
display dialog "The message URL:" & return & return & theclip & return & "is now on the clipboard."
end tell
--open location theURL

And here's the Ruby code (this could probably be done in perl, Applescript or anything you want, but I am learning Ruby and wanted to play with it some)


#!/usr/bin/env ruby
# => get clipboard contents as string
messageID = %x{pbpaste}.to_s
# => convert to message URL and encode non-alphanumeric as hexidecimal escapes
messageURL = 'message://' + messageID.gsub(/([^a-zA-Z0-9_.-]+)/n) {
'%' + $1.unpack('H2' * $1.size).join('%').upcase
}
# => open a pipe for output to pbcopy and print the new message URL
open("|/usr/bin/pbcopy","w"){|outf| outf.puts messageURL}

Hope this helps someone.

Norm

[ Reply to This | # ]

Link iCal events and to-dos to to any Mail message
Authored by: FlyBoy on Nov 15, '06 12:15:14PM

I forgot to note that the do shell script line in the applescript needs to have the path pointing to the location of the ruby script or perl script that performs the URL encoding.

Sorry for any confusion.

Norm



[ Reply to This | # ]
Link iCal events and to-dos to to any Mail message
Authored by: John M on Nov 16, '06 04:55:44AM
As FlyBoy states, you can do this without the Ruby script. I can't test this as I don't have MailTags.

Replace the following lines in the Applescript:
set the clipboard to theID 
do shell script "/Users/nacohen/bin/messID2messURL.rb" 
With:
set the clipboard to "message://" & (do shell script "python -c 'import sys, urllib; print urllib.quote(sys.argv[1])' " & quoted form of theID)
John M

[ Reply to This | # ]
Link iCal events and to-dos to to any Mail message
Authored by: inik on Nov 15, '06 01:34:48PM

This is a highly unreliable means of linking to messages.

If the message moves, the link is broken.

If you attempt to tag the message via an incoming mail rule, it will fail (the message ID isn't created yet)

If you rebuild your spotlight index, you can also break the link.

If it's an iMap message, you can also lose the link if you ditch your mail cache and re-download the message.

MailTags' approach is SLIGHTLY better, but still not that robust. There is no reliable way to link to mail messages from other programs. If you really want to keep 'em tied together, save the message as text (or rich text if you prefer) and attach that wherever you want or make aliases to it. Sure, it's not in mail, but it works.



[ Reply to This | # ]
Link iCal events and to-dos to to any Mail message
Authored by: smorr on Nov 15, '06 03:25:18PM

nice

--- just be aware that Mail will not respond to message:// unless mailtags is installed.



[ Reply to This | # ]
Link iCal events and to-dos to to any Mail message
Authored by: smorr on Nov 15, '06 03:29:06PM

Whoops This should be inresponse to flyboy



[ Reply to This | # ]
Link iCal events and to-dos to to any Mail message
Authored by: FlyBoy on Nov 15, '06 09:42:09PM
Hi,

Thanks. I hadn't realized or had forgotten that MailTags registered the message:// URL. I've been using MailTags (registered/paid) for quite awhile and I guess just assumed that this feature was a native part of the system, and not a MailTags provided goodness.

Oh well. More reason to get MailTags. By the way, the message:// url form works from ical whether or not I move the message. I don't use IMAP, so can't comment on its applicability with those accounts.

I saw on HawkWings <http://www.hawkwings.net/2006/11/07/mailtags-hyperlink-to-emails-in-other-apps/>; that the next version of MailTags will have a copy URL contextual menu for mail messages, making this script obsolete. Looking forward to that release!

Norm

[ Reply to This | # ]