Linking to a Contact from iCal
I am trying to set up a phone call in iCal. I'd like the alarm to go off ten minutes beforehand and open up the card for a specific person so I have their phone number there rather than having to look for it.
How do I link to the card file for him? I am sure this is easy, but I'm not finding it.
How do I link to the card file for him? I am sure this is easy, but I'm not finding it.
Comments
Originally posted by varian72
I am trying to set up a phone call in iCal. I'd like the alarm to go off ten minutes beforehand and open up the card for a specific person so I have their phone number there rather than having to look for it.
How do I link to the card file for him? I am sure this is easy, but I'm not finding it.
1. You mean the person's card in the Address Book.app?
2. Where is the person's name stored that you want the card for? Is it in iCal somewhere, or do you want to hard-code it?
Originally posted by lundy
1. You mean the person's card in the Address Book.app?
2. Where is the person's name stored that you want the card for? Is it in iCal somewhere, or do you want to hard-code it?
Yes, I mean the card in Address Book.app. The person's name is stored in Address Book. I don't want to hard code it....I want to simply attach the file from within the alarm function in iCal.
Originally posted by varian72
Yes, I mean the card in Address Book.app. The person's name is stored in Address Book. I don't want to hard code it....I want to simply attach the file from within the alarm function in iCal.
I'm working on it - so the idea is to match the "attendee" name in an iCal event to a Person Name in Address Book? At first glance it is giving me trouble, but I will consult MacScripter and see what they have to offer.
Here it is: copy and paste into Script Editor, save into ~/Library/Scripts, and then set it as the Alarm action in the Event that you want it to call.
property calendarName : "Home"
tell application "iCal"
set thisCalendar to first calendar whose title is calendarName
set theEvents to (every event of thisCalendar)
set theStartDates to (start date of every event of thisCalendar)
set currDate to (current date)
set todaysDateString to date string of currDate
set closest to currDate - (date "Thursday, January 1, 1970 12:00:00 AM")
repeat with i from 1 to count theStartDates
set thisStartDate to item i of theStartDates
set thisEvent to item i of theEvents
set thisCloseness to currDate - thisStartDate
if thisCloseness is not less than 0 then -- not in the future
if thisCloseness is less than closest then
set closest to thisCloseness
set closestEvent to thisEvent
end if
end if
end repeat
set theName to (display name of first attendee of closestEvent)
end tell
tell application "Address Book"
try
set ABFound to (first person whose name is theName)
set selection to ABFound
activate
on error
display dialog "Name of Attendee for Alarm not found in the Address Book."
end try
end tell
NOTES:
- the attendee name MUST be identical to what it is in the Address Book. Just use the popup in iCal to set the attendee from the Address Book.
- in this version, the script will run when the event Start Time happens. There is a bug in iCal that leaves all the Trigger Times blank. If this is an issue, I can kludge up my own Trigger Time by subtracting the Trigger Interval from the Start Time of the event.
- Before saving the script, replace the calendar name "Home" in the first line with the name of your calendar.
property calendarName : "Home"
tell application "iCal"
set thisCalendar to first calendar whose title is calendarName
set theEvents to (every event of thisCalendar)
set theStartDates to (start date of every event of thisCalendar)
set currDate to (current date)
set todaysDateString to date string of currDate
set closest to currDate - (date "Thursday, January 1, 1970 12:00:00 AM")
set thisTriggerInterval to 0
repeat with i from 1 to count theStartDates
set thisStartDate to item i of theStartDates
set thisEvent to item i of theEvents
try -- see if event has a trigger interval, and if so, save it
set thisTriggerInterval to trigger interval of first open file alarm of thisEvent
end try
set thisCloseness to currDate - thisStartDate - thisTriggerInterval
set thisTriggerInterval to 0
if thisCloseness is not less than 0 then -- not in the future
if thisCloseness is less than closest then
set closest to thisCloseness
set closestEvent to thisEvent
end if
end if
end repeat
set theName to (display name of first attendee of closestEvent)
end tell
tell application "Address Book"
try
set ABFound to (first person whose name is theName)
set selection to ABFound
activate
on error
display dialog "Name of Attendee for Alarm not found in the Address Book."
end try
end tell
There is no way to solve the prefix/suffix/middle name problem. Just type the Attendee into iCal exactly as it appears in the Address Book (e.g., "Meyer Paul MD", not just "Meyer Paul"), and it will find it.
Nice script. I tend to use the email feature already in iCal but this is something that should also already be in there.
I never liked iCal. It just doesn't seem obvious to me how to use the thing. I don't understand why a ToDo item can't be a telephone call complete with the person to call, etc. I don't understand why all the calendars show through each other. I don't understand why the only choices you have for an Event is either All Day or a specific time. You would think that it would always pull all the contact info from Address Book for ToDos and Events that include a Person, but not only does it not do that automatically, as this script shows, you can't even script it because it won't tell you what Event called your script!!
That said, the script only calls the first of all the attendees.
That's more of an AppleScript syntax thing than anything else. When you use a construct like "name of every person whose first name is 'Dubya'", then it returns a list, even if there is only one item in the list. So you have to use the construct "first xxx" or "item 1 of xxx" to coerce it to not be a list - otherwise you get an error that it can't make it into a reference, which is true. For setting the selection in Address Book, a list may work, but a single-item list usually won't work for many other apps. I don't know why AppleScript returns a list when there is only one item.
This is because it is opening address book and that will only show one contact at a time. What I would find most helpful would be a new window opening that has:
1. Event name and time
2. A list of attendees with their phone number and email
The reason I think a new window would be good is because if ical is hidden, the address book will open and the card will show but no reason. That and it only showing one attendee make having a new window necessary.
I suppose we could have the script put a message into the "Note:" field of the person's Address Book card that had the details of the event. What I really wanted to do was figure out how to access the "Large Type" menu item of the phone number field and have that showing when the card was displayed. I think the only way to do it is with GUI scripting though.
Reg, I hit the wrong button when trying to reply to your post. My sincere apologies.
Again nice script.
reg