Applescript for iCal question

In setting an alarm for a birthday calendar event I noticed that the sound file I had selected previously was no longer working. I wanted to change the alarm sound for ALL the birthdays in the year. I’ve looked for an applescript that would batch change all the birthday alarms, but I haven’t found one to do that.

I did find an applescript that would let me change the sound used in an alarm and I played with the idea of manually inserting that applescript for every birthday on my calendar. Then if I chose to change the sound file for all the birthdays I would only have to change the applescript. Well, that worked fine, except that now there was no way to get a message displayed for the event. The sound played but there wasn’t any message. I realized that I could easily miss hearing the sound alert and needed the message displayed but there wasn’t any way to have that option. It was either play the applescript file or have a separate sound and message. So it would be back to the way it was.

My questions are: Does anyone see a way to have one applescript file to use for all the birthday events and therefore let me change the sound file for all the birthdays by just changing the applescript file, but yet have the message displayed so I wouldn’t miss it?

Is there any way to batch change events for the entire year calendar?

Thanks for any help.
Art

Model: MacBook Pro
AppleScript: 2.1.1
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

Hi Art,

this script changes all alarm sounds of the calendar “Bithdays” to e.g. “bottle”.
I assume, this is not the automatically generated calendar from Address Book,
AFAIK it’s not possible to change anything in that calendar

property MySound : "Bottle"

tell application "iCal"
	tell calendar "Birthdays"
		repeat with i in events
			if (count sound alarms of i) > 0 then
				repeat with ii in sound alarms of ii
					if sound name of ii is not "" then set sound name of ii to MySound
				end repeat
			end if
		end repeat
	end tell
end tell

Thanks for the info. I tried running the script but got an error that said ii wasn’t defined. Here’s the script I ran:

property MySound : "Hero"

tell application "iCal"
	tell calendar "test"
		repeat with i in events
			if (count sound alarms of i) > 0 then
				repeat with ii in sound alarms of ii
					if sound name of ii is not "" then set sound name of ii to MySound
				end repeat
			end if
		end repeat
	end tell
end tell

I tried to figure out what the variable i and ii were but had some trouble. I figured they were just counters but I couldn’t see how they were initialized.

Art

Model: MacBook Pro
AppleScript: 2.1.1
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

sorry, try this:


property MySound : "Hero"

tell application "iCal"
	tell calendar "test"
		repeat with i in events
			if (count sound alarms of i) > 0 then
				repeat with ii in sound alarms of i -- one i too much ;)
					if sound name of ii is not "" then set sound name of ii to MySound
				end repeat
			end if
		end repeat
	end tell
end tell

Ahh! That made a difference. I noticed as I ran the script on my actual birthday calendar (of which there are 97 entries for the year) that the event log, as it was running, showed the counter climbing to item 290. That means, I guess, that it went out three years (remember that all of those 97 entries are annual recurring events) and made changes. I made the calendar go out to 2040 and checked one of the birthday events and it showed that it had made the change. Is there a default cut-off point that the script will run for recurring entries? Why did it just stop at three years? Why not stop at one year? Just wondering? The script works great and it will be a perfect addition to my script menu and be a lot easier than trying to do it the way I thought it was probably going to have to be done. In effect, this is a “batch change” script, which is just the ticket. I can see where I could modify this to batch change my anniversary calendar or any other event which is recurring and I want to change the alert sound, or even other properties of the alarm.

Although, as I think about this, I notice that the script says to tell the calendar “whatever” and it changes every alarm in that calendar to a particular sound. Hmmmm… I suppose I would have to have it search for a keyword in the event title in order to make it a true “batch-change” script.

Well, I am grateful for your help.

Art

Model: MacBook Pro
AppleScript: 2.1.1
Browser: Safari 419.3
Operating System: Mac OS X (10.4)