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
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
Post
Replies
Boosts
Views
Activity
Hello!
I am trying to make a script that will show a dialog box and at the same time loop through some code. I cannot find a way to do this, does anybody know how? Below is sort of how I want the code to work.
Thanks!
applescript
set thedialog to display dialog "A dialog box"
repeat while thedialog = true
set TimeUntilButtonPress to TimeUntilButtonPress + 1
delay 1
end repeat-This is incorrect, its just an example of how I want the code to work
I am trying to make an Applescript code that uses variables to stop a repeat loop, and I keep getting an error that the variable "result" is not defined. Here is my code:
set x to 0
display dialog "test" buttons {"Ok"}
repeat 4 times
if result = {button returned:"Ok"} then
set x to x + 1
display dialog "test" buttons {"Ok"}
if x = 4 then
display dialog "test successful"
exit repeat
end if
end if
end repeat
I keep getting this error:
The variable result is not defined. Can someone explain to me why this keeps happening?
Thanks, I really appreciate it!