Applescript Crashing on Infinite Loop I am trying to use applescript to wait for a Serial keyword (in Screen - in Terminal), and then pausePlay Spotify when the keyword is seen.  It works fine at first, but then quickly crashes.  Can someone please let me know what I am doing wrong?

Thanks in advance.

I am sorry, but I can't seem to get the Applescript code to format properly here...
Here is the Applescript code:

tell application "Terminal"
    set the bounds of window 1 to {0, 0, 500, 100}
end tell

set trigger to 1

set stopString to ""

repeat until (stopString = "stop")

    tell application "Terminal"

        if the contents of window 1 contains "Start MP3" and trigger is 1 then
            tell application "Spotify" to playpause
            set trigger to 0
        end if

        if the contents of window 1 does not contain "Start MP3" then
            set trigger to 1
        end if

        if the contents of window 1 contains "Stop Loop" then
            set stopString to "stop"
        end if


    end tell
end repeat
Like all while/do (Applescript repeat) loops, you must ensure a condition is met for it to exit.

How do you ensure that a condition will be met and not go on infinitely?  From what I can tell you have a window that can contain "Start MP3" or "Stop Loop."  What if it contains "I love balloons" or is blank?

You haven't created any logic for this (error trapping) so this loop will repeat until the window meets the condition to stop. 

To prevent that you to put in a fail safe that sets the condition that stops the loop.  You can do this  by adding a counter and checking the counter against a predetermined value that will force condition that stops the loop to become true.

For example, we set a limit that the loop will run 10 times:

set count to 0

repeat until (stopString = "stop")

    ...


    if count &gt; 10 then
        set stopString to "stop"
    end if

    set count to count + 1

end repeat