There seems to be a lot of confusion as to what days the Twelve Days of Christmas start on–and even why there is such a thing as the Twelve Days of Christmas. Some say that the earliest Christians celebrated January 6 as the birthday of the Christ child and that it wasn’t until over three hundred years later that the date was set for December 25. Whatever the reason and the season, somebody came up with a song that may have something to do with the 12 days of Yuletide which begins December 22. And for you, who want to do something silly for the Holidays, here is a script that demonstrates using repeat loops to have your Macintosh “sing” the silly song. (Experiment with the values for the voice, speaking rate, pitch, and modulation just for fun.)

Copy the script into the AppleScript editor and save it using Application as the File Format (without options checked). Make sure you have sound turned on when you double click on the file to run the script.


set theCounters to {"First", "Second", "Third", "Fourth", "Fifth", "Sixth", ¬
"Seventh", "Eighth", "Ninth", "Tenth", "Eleventh", "Twelfth"}
set theCounted to {"a partridge in a pear tree.", "two turtle doves, and ", ¬
"three French hens, ", "four calling birds, ", "five golden rings, ", "six geese a-laying, ", ¬
"seven swans a-swimming, ", "eight maids a-milking, ", "nine ladies dancing, ", ¬
"ten lords a-leaping, ", "eleven pipers piping, ", "twelve drummers drumming, "}
set thisList to {}
set countedSoFar to ""
repeat with n from 1 to 12
	set countedSoFar to item n of theCounted & countedSoFar
	set thisPhrase to "On the " & item n of theCounters & ¬
" Day of Christmas, my true love sent to me: " & countedSoFar
	set end of thisList to thisPhrase
	say thisPhrase using "Alex" speaking rate 140 pitch 42 ¬
modulation 60 with waiting until completion
end repeat


Notice in the above how the parameters for the say method are added following the direct parameter which defines the voice. With the exception of the direct parameter, which must directly follow the handler name, labeled parameters can appear in any order, with the labels from the handler definition identifying the parameter values. This includes parameters listed in given, with, and without clauses (of which there can be any number). With the exception of display dialog, can you think of any other methods in AppleScript which use labeled parameters?