System Events not running

Hello!
I made an AppleScript that uses variables that changes by 1 every second, in the original version, it just tells System Events to type, but I kept getting errors so I changed it to tell System Events to activate and type something. The code works, but on the lines of code that tell System Events to activate, at a random time I get an error saying System Events is not running on the line of code telling it to activate. I am very confused. I will attach the error message as well as the code. The code is from a friend, I am just posting it for him.


Script Error
Application isn't running



Code Block applescript
tell application "System Events" to activate
tell application "System Events" to activate
set beg to 0
set mc to 0
set hour to 0
set search to 0
set pet to 0
set hl to 0
set ud to 0
set pm to 0
set ud to 0
set searchresult to 0
set listhl to {"h", "l"}
set listpm to {"f", "k"}
set listsearch to {"north pole", "advent calendar", "mistletoe", "christmas tree", "christmas card"}
delay 1
set ud to some item of listhl
set pm to some item of listpm
set searchresult to some item of listsearch
set reset to 0
delay 9
tell application "System Events"
keystroke "pls daily"
key code 36
delay 0.5
keystroke "pls beg"
key code 36
delay 0.5
keystroke "pls hunt"
key code 36
delay 0.5
keystroke "pls fish"
key code 36
delay 1
keystroke "pls hl"
key code 36
delay 2
keystroke ud
key code 36
delay 2
keystroke "pls pm"
key code 36
delay 2
keystroke pm
key code 36
delay 2
keystroke "pls search"
key code 36
delay 1
keystroke searchresult
key code 36
set ud to 0
set pm to 0
set searchresult to 0
delay 1
set ud to some item of listhl
set pm to some item of listpm
set searchresult to some item of listsearch
repeat
set beg to beg + 1
set mc to mc + 1
set hour to hour + 1
set search to search + 1
set pet to pet + 1
set hl to hl + 1
delay 1
if hl = 22 then
tell application "System Events" to activate
tell application "Google Chrome" to activate
tell application "System Events"
set hl to 0
keystroke "pls hl"
key code 36
delay 1
keystroke ud
key code 36
set ud to 0
delay 1
set ud to some item of listhl
end tell
end if
if beg = 47 then
tell application "System Events" to activate
tell application "Google Chrome" to activate
tell application "System Events"
keystroke "pls beg"
key code 36
set beg to 0
end tell
end if
if mc = 62 then
tell application "System Events" to activate
tell application "Google Chrome" to activate
tell application "System Events"
set mc to 0
keystroke "pls hunt"
key code 36
keystroke "pls fish"
key code 36
delay 6
keystroke "pls pm"
key code 36
delay 2
keystroke pm
key code 36
set pm to 0
delay 1
set pm to some item of listpm
end tell
end if
if hour = 3600 then
tell application "System Events" to activate
tell application "Google Chrome" to activate
tell application "System Events"
keystroke "pls hourly"
key code 36
delay 1
keystroke "pls daily"
key code 36
set hour to 0
end tell
end if
if search = 37 then
set search to 0
tell application "System Events" to activate
tell application "Google Chrome" to activate
tell application "System Events"
keystroke "pls search"
key code 36
delay 1
keystroke searchresult
key code 36
set searchresult to 0
delay 1
set searchresult to some item of listsearch
end tell
end if
if pet = 1800 then
set pet to 0
tell application "System Events"
keystroke "pls pet pat"
key code 36
keystroke "pls pet feed"
key code 36
if reset = 50 then
set reset to 0
tell application "System Events" to activate
end if
end tell
end if
end repeat
end tell
end
end
end
end
end
end



Hi there,

Same issue for me except I was using keystroke on an application.

I simply fixed this issue by restarting my mac then adding tell application "System Events" to activate. That seems to do the trick.

Also I dont think the dank meemer bot team would be too happy about you running automation, it is also against Discord's inc terms of service for "self botting".

Kief

System Events not running
 
 
Q