Automator to create emails into iCal events

Discussion in 'Mac Programming' started by TVPost, Feb 14, 2009.

  1. macrumors newbie

    Joined:
    Feb 14, 2009
    Location:
    Los Angeles
    #1
    If anyone feels this would be better posted in another site, please let me know. This seems like the best place for my question:

    I have searched for solutions to this automator need but have failed.

    I need to document in iCal 100's emails from the last 3 years from over a dozen recipients. The script / automator task is too complex for my current automator skills.

    Specifically, automator need is:

    Plug in a email sender's address (using Mac "Mail") and have it create corresponding iCal events for all the emails from that sender in iCal ON the date the email was sent.

    I need the events to have the subject of the emails in them OR a standard name that I can manually change in iCal (or both) and the created event link to each email that created it.

    We're looking at maybe two dozen different senders covering a period of three years. So, doing this manually is not someting I can do in any reasonable amount of time, and comprehensive and accurate are requirements.

    Thanks in advance for any help.

    Pete
     
  2. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #2
    I was sort of curious, b/c it seemed applescript should be able to handle this pretty easily... but then i saw:
    "...created event link to each email that created it"

    and don't have any idea what you mean. Would the idea be that you could click some sort of hyperlink and have mail open the message? There is a unique ID for each message, but it seems like you may need a separate applescript that would be run on an event in ical that would open the id stored in the note field or something like that.

    You may want to clarify this, but otherwise this definitely seems within the realm of possibility.

    -Lee
     
  3. thread starter macrumors newbie

    Joined:
    Feb 14, 2009
    Location:
    Los Angeles
    #3
    Thank you Lee

    In, iCal, if, when you receive an email, you click on the date on the email and select "create new ical event" it will not only create an event, on that date, but yes, there will be a hyperlink to the email you started with.

    Since you're my first post, I'm new to automator and been following demos online to understand simple tasks, but I don't know simple text, so whatever the solution is (and I am confident there is one) I'll need a bit of handholding on this, my first, complex creation.

    Thanks for replying!

    P
     
  4. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #4
    Hm. I am a bit perplexed. I am looking in mail, and have tried clicking and ctrl+click everywhere i can think, and never see the "create new ical event" option. Is this an applescript or special extension you've installed? Perhaps this is available only in Mail.app on 10.5 (I am using 10.4)? I wanted to see the style of the link that was created, to see if it would easily be mimicked(or supported directly via an applescript dictionary).

    -Lee
     
  5. thread starter macrumors newbie

    Joined:
    Feb 14, 2009
    Location:
    Los Angeles
    #5
    Hi again Lee.

    Yes, this may be a 10.5 feature (10.5.6 in my case), but frankly, if I can just create the event (on the proper dates corresponding to all the emails from a particular sender) by plugging in the email address and create a predetermined name for the event in iCal (such as "email from Lee 2B renamed) that would be great! Once I have that in iCal, most of the work is done for me. I can manually do the rest.

    If you have any ideas on how to do that, I'd really appreciate it.
     
  6. thread starter macrumors newbie

    Joined:
    Feb 14, 2009
    Location:
    Los Angeles
    #6
    Anyone else reading these posts, Lee has brought out a few specifics I didn't think to add (thanks Lee). If anyone knows of such an automator task for download, PLEASE share the url. If anyone is inspired by this challenging (in my opinion) task and is willing to take a crack at it, I'd be really appreciative.

    I need to have this calendar timeline in about one week for an urgent matter.

    Thanks!

    Pete
     
  7. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #7
    Code:
    display dialog "Address to generate events for: " default answer "user@domain.com"
    set diagRet to result
    set searchString to text returned of diagRet
    tell application "Mail"
    	set myInbox to mailbox "INBOX" of account 1
    	set myMessages to every message of myInbox where sender is searchString
    	
    	repeat with theMessage in myMessages
    		set alt to sender of theMessage
    		set sdr to sender of theMessage
    		set dt to date received of theMessage
    		set sm to id of theMessage
    		set sub to subject of theMessage
    		tell application "iCal"
    			set myCal to calendar "Test"
    			make new event at the end of events of myCal with properties {summary:"Email from " & sdr & ": " & sub, description:sm as text, start date:dt, end date:dt}
    			display dialog ("Creating " & dt)
    		end tell
    	end repeat
    end tell
    
    This applescript should cover it. The display dialog "Creating" line can be pulled out, that was just for seeing what was going on.

    I really don't know about linking back to emails. There is a URL property of iCal events, but i wouldn't know how to link to it. The description is being set to the unique ID of the message in Mail.app. I'm guessing that can somehow be used to link back, but i have no idea how.

    -Lee
     
  8. thread starter macrumors newbie

    Joined:
    Feb 14, 2009
    Location:
    Los Angeles
    #8
    Thank you Lee. Almost perfect!

    Lee, thank you so much for this script. i was trying to figure something out, but was not remotely close to this. This is great. I plugged in an address and the only issue is that it only creates ONE event from ONE email from the defined sender. It does not create an event from every email from that sender.

    Any idea how to resolve that?

    (FYI, the only change I made to the scrip was to put in a real email address in place of your "user@domain.com". Is there another variable?)

    Thanks again!

    P
     
  9. thread starter macrumors newbie

    Joined:
    Feb 14, 2009
    Location:
    Los Angeles
    #9
    One more thing Lee, I have several email accounts I am searching. I'd like all the accounts in my inbox to be searched. Perhaps, that's why I'm only getting the one result.

    P
     
  10. thread starter macrumors newbie

    Joined:
    Feb 14, 2009
    Location:
    Los Angeles
    #10
    Lastly, I tried one email right away, and got the dialogue box for one email.

    I then tried a different email address, and got no dialogue box and "no results" dsiplayed.

    I know this is the script, I need to build on

    finding ALL emails from one sender at a time (the dialogue box is a good idea as I can reject some I don't want) from all my mail accounts is where it is haning up.

    Thanks again, very kind of you to take the time. I know what I'll be doing for the next 4 hours.

    P
     
  11. macrumors 68040

    lee1210

    Joined:
    Jan 10, 2005
    Location:
    Dallas, TX
    #11
    Unfortunately I'm not at my computer. There would be a way to loop through the accounts. I only have one, and the script seemed to pick everything up, not just the first. Clicking cancel at any time stopped script execution. I'm sure there's a way to control it more specifically, I'm just not that familiar with AppleScript.

    Good luck with modifications. I can take a look again tomorrow night.

    -Lee
     
  12. thread starter macrumors newbie

    Joined:
    Feb 14, 2009
    Location:
    Los Angeles
    #12
    Thanks, new tread of same need...

    Thanks Lee

    I'm going to need to compile this calendar by end of day Sunday, so I'm doing my best to try to make it work.

    To keep things simple, I've created a new tread starting with your script and an explanation of my needs.

    Thanks again for your generous help.

    New Tread: http://forums.macrumors.com/showthread.php?p=7131609#post7131609

    P
     

Share This Page