For the sake of full disclosure, this was written with bananas, not apples. The doctor may not be kept away.
With AppleScript highlighting:
For Copy&Pasting:
activate application "TextEdit"
tell application "System Events"
repeat until first window of application "TextEdit" exists
tell application "TextEdit" to make new document at the front
delay 1.0E-3
end repeat
repeat until process "TextEdit" is frontmost
set frontmost of process "TextEdit" to true
delay 1.0E-3
end repeat
set focused of first window of process "TextEdit" to true
repeat with i from 1 to 100
if i mod 15 is 0 then
keystroke "FizzBuzz"
keystroke return
else if i mod 3 is 0 then
keystroke "Fizz"
keystroke return
else if i mod 5 is 0 then
keystroke "Buzz"
keystroke return
else
keystroke i
keystroke return
end if
end repeat
end tell
I borrowed the logic for appropriately waiting for "TextEdit" to be ready to receive text from this excellent Code Review answer.
I feel like I want to write functions... but I don't know what's available in AppleScript for modularizing code... err script... I'm just getting my toes wet here.