pick events from iCal and put them in mail.app

Hi everyone…

I have been working on a script to select iCal events (out of a selected calendar) and automatically paste the information into a new mail document… So far I have several issues that I need help with… First-- here is my script:

set string_fun to 1
set list_number to 0
set event_choose to {}
set final_location to “”
set final_url to “”
set final_description to “”
set final_status to “”

tell application “iCal”
activate
set visible of window “iCal” to true
set the_cal to the title of every calendar
set list_choice to (choose from list the_cal)
set list_string to (list_choice as string)
repeat with list_number in the_cal
set descriptionval to {item string_fun of the_cal} as string
if descriptionval = list_string then
else
set string_fun to string_fun + 1
end if
end repeat
set event_list to calendar string_fun’s events
repeat with event_cur in event_list
tell event_cur
set editdate to (start date as string)
set the end of event_choose to editdate & " " & summary
end tell
end repeat
tell event_cur
set final_summary to summary
set final_startdate to start date
set final_enddate to end date
– set final_location to location
– set final_url to url
– set final_description to description
– set final_status to status
end tell
set event_choice to (choose from list event_choose)
end tell
set the_sub to “Calendar Information”
set the_sender to “”
set the_message to “Automatic iCal email notifaction!” & return & return & "Event Summary: " & final_summary & return
set the_message to the_message & "Event Start Date: " & final_startdate & return
set the_message to the_message & "Event End Date: " & final_enddate & return
if final_location ? “” then
set the_message to the_message & "Event Location: " & final_location & return
end if
if final_url ? “” then
set the_message to the_message & "Event URL: " & final_url & return
end if
if final_description ? “” then
set the_message to the_message & "Event Description: " & final_description & return
end if
if final_status ? “” then
set the_message to the_message & "Event Status: " & final_status & return
end if
tell application “Mail”
set k to make new outgoing message with properties {subject:the_sub, content:the_message}
tell k to make new to recipient at end of to recipients with properties {address:the_sender}
send k
end tell

********************************** END OF SCRIPT ****************************

ok… here are my issues:

#1. in my list of events after chosing a calendar… I have gotten the (start date) — Somehow this looks identical in format to (current date) … however, if I try to make the code read:

set editdate to (the day of (start date) as string)

i get an error… and I tried over and over many different ways to do this… because I dont want the whole “THURSDAY, SEPTEMBER 20, 2004 12:41 AM” by each iCal event… I honestly just want something simple like “9/20/04” or maybe have the time also on there… but I could not figure out this at all— Which brings me to another question… How can you capture parts of a string? Back in the world of basic programming, you could say a$=right$(b$,5), and that would give you the last 5 characters of b$… or a$=left$(b$,3) for the first 3… or a$=mid$(b$,3,3) for 3 characters after the third character from the left… Is there something similar in applescript?

#2. in my initial list for “choose your calendar”-- Is there a way to include a 3rd button which would execute a separate part of my script? What I would like is another option to have this script function soley off of what is currently highlighted in iCal-- Could not figure out how to accomplish this at all (why are the AS dictionaries full of such little information and so difficult to interpret!!!)

#3. with the way I have my script right now… It is trying to automatically send out the mail-- and I get an error because there is no email address specified (which I don’t want there to be)… I could not figure out how to actually make mail just create a new document full of this text and have it appear on the screen… It seems that without the “send k” it doesn’t always show up.

#4. I had to comment out 4 statements for final_location, final_url, final_description, and final_status… Because if iCal didn’t have these values defined, it freaked out… Which I tried to in the beginning of the script define them as “”… However, once the script ran through the event and attempted to get all the data-- it seems to not really hold “” but it actually holds (non-existance)… So is there a way to say … if final_url is non-existant then set final_url to “” ???

#5. How do I specify Fonts & text size within mail? I tried the whole “set the font to “arial””… but I get an error for that syntax…

I think those were my major issues…

Thank you all for your time and help… it is much appreciated!

ok I figured out the the issue I was having with the new mail message show up without the ‘send k’…

But I also am noticing that I am having problems finding out how to get the “notes” field from within iCal… There is no description of notes in the dictionary… Does any one have any idea what I need to do to get that data?

thanks.

Use the offset function. A weblink I used is:

http://maccentral.macworld.com/features/applescriptprimer35/

I just had the same question. It was a hard one to find.