Here's the adjusted code to only add an alarm to events that have no [display] alarm:
Code:
tell application "iCal"
set iCalendars to {}
set theCals to {}
set theCals to calendars
repeat with i from 1 to count of theCals
copy title of item i of theCals to end of iCalendars
end repeat
set i to 1
repeat with currentCalendar in iCalendars
if item i of iCalendars is equal to "Birthdays" then
set CalNum to i
exit repeat
end if
set i to i + 1
end repeat
set currentCal to item CalNum of theCals
set theEvents to events of currentCal
repeat with i from 1 to count of theEvents
if (count of display alarms of item i of theEvents) is equal to 0 then
make new display alarm at end of display alarms of item i of theEvents with properties {trigger interval:-7200}
end if
end repeat
end tell
I'm not sure how to automatically run it every time you make a new event. AFAIK, iCal has no Scripts menu, but you can open /Applications/Applescript/Install Script Menu to add a Scripts menu to the right of the menu bar. Then go to Home/Library/Scripts and create a folder called 'iCal Scripts'. Save the above script there. You can then quickly run the script from the Scripts menu.
Another option would be to use a script to create each event, which will then automatically create an alarm for it. Something like this:
Code:
tell application "iCal"
set iCalendars to {}
set theCals to {}
set theCals to calendars
repeat with i from 1 to count of theCals
copy title of item i of theCals to end of iCalendars
end repeat
set i to 1
repeat with currentCalendar in iCalendars
if item i of iCalendars is equal to "Birthdays" then
set CalNum to i
exit repeat
end if
set i to i + 1
end repeat
set currentCal to item CalNum of theCals
set {theAction, theDescription} to {button returned, text returned} of (display dialog "What is a description of the event" buttons {"OK", "Cancel"} default button "OK" default answer "New Event")
if theAction is equal to "OK" then
set {theAction, theDate} to {button returned, text returned} of (display dialog "What date is this event?" buttons {"OK", "Cancel"} default button "OK" default answer "")
if theAction is equal to "OK" then
set theNewEvent to make event at end of events of currentCal with properties {summary:theDescription, allday event:true, start date:date (theDate), recurrence:"FREQ=YEARLY"}
make new display alarm at end of display alarms of theNewEvent with properties {trigger interval:-7200}
end if
end if
end tell
This script prompts you for a summary and date for a new event, and then creates it in the calendar "Birthdays". It makes the event an allday event, and also makes it repeat each year. Then it creates a display alarm for the event which appears 5 days before the event.
Note that, when you specify a date, the easiest way is to specify it in the format MM/DD/YY or DD/MM/YY, depending on your date settings. AppleScript is flexible, so you could put something like MM/D/YYYY instead.
The way I learnt AppleScript was to look at other people's scripts and see how they did things. I then started by writing scripts with the things I understood (I think display dialog was the first thing I did), and developed on that.
When you want to do things with a particular application, that code has to be enclosed in a tell block. In Script Editor, if you go to File->Open dictionary, then it will display a list of all scriptable applications on your computer. Select the appropriate application and it will tell you what you can do with the application (it will probably be a bit confusing at first though).
Apple has also documented AppleScript at
http://developer.apple.com/documentation/AppleScript/. Pay special attention to the 'Getting Started' link.
Good luck, and happy scripting.