Can I run a script in the background? (Apple script editor) I have a script on apple script editor for a discord bot. (Discord is a chatting app my friends and I use) The discord bot is called "Dank Memer" and basically there are coins that you can get by typing in certain commands, such as "pls beg". I have a bot that I can run overnight to farm coins, the problem is that i need my laptop to be on that window to run it, since all it does is type the command and then press return. I was wondering if I could run the script in the background so I can farm coins 24/7.

Here's the code.

tell application "System Events"
    repeat
        delay 40
        keystroke "pls beg"
        keystroke return
    end repeat
end tell
No, System Events can only send keystrokes to the frontmost window and is not capable of sending keystrokes to a window  that's in the background.