Your prescription for increased productivity and profitability
In the spirit of the season we will look at a script that takes advantage of a repeat loop and text concatenation to create the Twelve Days of Christmas.
The AppleScript version is especially effective if played on a Macintosh with sound turned on. Just for fun, change the value for the variable theVoice at the top of the script to one of the voices installed on your computer. To see a list of the voices, open the Dictation & Speech panel under the system Preferences. In the tab for Text to Speech you should have names such as Alex, Bruce, Fred, Kathy, Vicky, and Victoria (the list changes depending on your system).
The ExtendScript version simply shows the result for each day of Christmas in an alert dialog.
Copy the appropriate script into your favorite editor. Run the script and enjoy. If you are using the ExtendScript version, be prepared to dismiss alert dialogs.
set theVoice to "Victoria" 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 theseThings to {} set countedSoFar to "" repeat with n from 1 to 12 set countedSoFar to item n of theCounted & countedSoFar set thisThing to "On the " & item n of theCounters & " Day of Christmas, my true love sent to me: " & countedSoFar set end of theseThings to thisThing & return say thisThing using theVoice with waiting until completion end repeat
var theMax = 12; var theCounters = ["First", "Second", "Third", "Fourth", "Fifth", "Sixth", "Seventh", "Eighth", "Ninth", "Tenth", "Eleventh", "Twelfth"]; var theCounted = ["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,"]; var theseThings = []; var countedSoFar = ""; for (var n = 0; n < theMax; n++) { var countedSoFar = theCounted[n] + countedSoFar; var thisThing = "On the " + theCounters[n] + " day of Christmas, my true love sent to me: " + countedSoFar; theseThings.push(thisThing); alert (thisThing); }
In the scripts, notice how items in the lists are selected within the repeat loop and concatenated into the string defined by thisThing. The variable thisThing is then added to the array theseThings.
The value of the variable theseThings created by the script is itself an array of each day’s result. This could be used in a variety of ways. If you come up with a great way to use the array, please email me at shopkins.com with the subject “Script Idea.”
Thanks for reading my blog, and do have a very enjoyable Christmas season.