Applescript- I made an auto scrolling code and need to know how to stop it Edit: This is the most recent code I have now... How can I get it to stop (change the value of x) when I run a separate script? 

    set x to 0

tell application "Google Chrome"
    set urlName to URL of active tab of front window
end tell

if urlName is "https://www.facebook.com" then

    tell application "System Events"
        tell application process "Google Chrome"
            set frontmost to true
            repeat while x = 0
                key code 38
                delay 1
            end repeat
        end tell
    end tell

else

    tell application "System Events"
        tell application process "Google Chrome"
            set frontmost to true
            repeat while x = 0
                key code 49
                delay 1
            end repeat
        end tell
    end tell

end if
I have redone the script, again. That code before was ridiculous tbh. I got a little ahead of myself... Let's try this again... Save this as a "stay open" application again, named anything. You'll just have to quit it when you want to stop scrolling, and start it up again when you want to continue. I advise putting it on your Dock for easy access:

global script_PID
on run
    tell application "Google Chrome" to activate
    delay 1
    tell me to activate
end run

on idle
    tell application "Google Chrome"
        tell active tab of front window
            set urlName to URL
            if (execute javascript "if (window.pageYOffset + window.innerHeight &gt;= document.body.clientHeight){true;}else{false;}") is false then
                execute javascript "window.scrollBy(0,window.innerHeight - 40);"
            else
                tell me to quit
            end if
        end tell
    end tell
    return 1
end idle


Tell me if you have any issues with this.