Writing FizzBuzz like this makes me feel like a small child 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&amp;Pasting:
activate application &quot;TextEdit&quot;
tell application &quot;System Events&quot;
    repeat until first window of application &quot;TextEdit&quot; exists
        tell application &quot;TextEdit&quot; to make new document at the front
        delay 1.0E-3
    end repeat
    repeat until process &quot;TextEdit&quot; is frontmost
        set frontmost of process &quot;TextEdit&quot; to true
        delay 1.0E-3
    end repeat
    set focused of first window of process &quot;TextEdit&quot; to true
    
    repeat with i from 1 to 100
        if i mod 15 is 0 then
            keystroke &quot;FizzBuzz&quot;
            keystroke return
        else if i mod 3 is 0 then
            keystroke &quot;Fizz&quot;
            keystroke return
        else if i mod 5 is 0 then
            keystroke &quot;Buzz&quot;
            keystroke return
        else
            keystroke i
            keystroke return
        end if
    end repeat
end tell

I borrowed the logic for appropriately waiting for &quot;TextEdit&quot; 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.
It may be fun watching it type out FizzBuzz, but interacting with the UI directly has its pitfalls. For example, if the user focuses a different application while your script is running, you will now be typing in the wrong place; and if you refocus the application, that could be annoying.

Fortunately, there is a better way. Rather than activating the application, waiting until a window appears, and making the window frontmost, you could just…

tell application "TextEdit" to set text of first document to "Hello, world!"


This is much less problematic. The only issue is if TextEdit is already open, in which case it will overwrite the existing document. In that case, you could use

tell application "TextEdit" to set text of (make new document) to "Hello, world!"


Either way, you’re not interacting directly with the UI any more, which eliminates a lot of potential problems.

The actual meat of the FizzBuzz implementation (barring the use of keystroke) looks fine, although you might consider something like keystroke "FizzBuzz" &amp; return rather than keystroke "FizzBuzz" and separately keystroke return.