iCal Help

I’m trying to write some applescript for iCal, but so-far I cannot find any documenataion or examples for this. If anyone knows of a good souce of this, I would be very gratfull.

If not, I have a couple of sticking points, maybe someone has the code of this:

  1. I have a folder of vCal files, I would like to import these to iCal, each as a new calendar. If you drop a vCal file from the finder into the calendars pane of iCal - it does what I want - but it needs to be in a script.

  2. Once the calendar is imported (or as the calendar imports), I want to re-colour it. Seems simple - but can’t get it working!

Thanks in advance for your time

Ben Robinson

Hi,

Importing a calendar into iCal is simple as adding it to the Calendar folder. I’m thinking about how to change the color.

gl,

Don’t try that yet.

Edit: is it alright if you temporarily lose the icons of all calendars in the Calendar folder until you restart your computer?

Edit: and about the colors. You can probably change to the default colors. If you want custom colors, I don’t know how.

gl,

Thanks for your reply,

I don’t see a problem with losing icons, although I’m not quite sure what you mean. When the script is finished I will only have new calendars in iCal, all exisitng calendars get deleted and I import new ones. So any settings on the calendars are irrelevant!

If I can only change to the default colours that should be fine - if thats all I can do.

Do you have an example?

Cheers

Ben

Hi,

Sorry, my cable broke and rr took 2 days to get here. Here’s a workaround to the read only tint setting. Maybe you can shorten it. I lost my train of thought.

property tint_list : {“blue”, “orange”, “teal”, “red”, “green”, “purple”}

set test_vcal to (choose file) – choose a vcal file
tell application “iCal”
activate
set temp_list to {} – list of temporary new calendar names for later deletion
– make temporary calendars until a red tinted calendar is made and delete it
– then next calendar made will have red tint
repeat with this_tint in tint_list
set temp_cal to (make new calendar with properties {title:this_tint})
if tint of temp_cal is “red” then
delete temp_cal
exit repeat
end if
set end of temp_list to this_tint
end repeat
end tell
– get Calendar folder reference for the current user
set user_lib_path to (path to “dlib” from user domain) as string
set cal_folder_ref to (user_lib_path & “Calendars”) as alias
– duplicate user selected vcal to the Calendars folder
tell application “Finder”
duplicate test_vcal to cal_folder_ref – or move
end tell
tell application “iCal” to quit – maybe not needed, thinking about the file icons
tell application “System Events”
repeat while (exists process “iCal”)
end repeat
end tell
– delete the temporary color calendars
tell application “iCal”
launch
activate
repeat with this_cal_name in temp_list
set this_cal to (first calendar whose title is this_cal_name)
delete this_cal
end repeat
end tell

gl,