0

What I am trying to do is make my character run up 50 steps then down 50 steps repeatedly using the up key and the down key. I know how to utilize system events to push keys and I know how to tell applications to do certain things but what I put together so far is not looking right. I am pretty much new to this, and I am trying to learn a bit, please help!!

2
  • What goes wrong when you try? It's hard to help you more without knowing what isn't working. – Daniel Jul 8 '13 at 19:53
  • Alright so my application is PokeMMO and I got an AppleScript Error it says PokeMMO got an error: AppleEvent timed out – Alex Kane Jul 8 '13 at 20:07
2

You might also add a delay somewhere in the loop to make it easier to stop the script:

activate application "TextEdit"
delay 0.5 -- time to release modifier keys if the script is run with a keyboard shortcut
tell application "System Events"
    repeat while name of (process 1 where frontmost is true) is "TextEdit"
        repeat 50 times
            key code 126 -- up
            delay 0.1
        end repeat
        repeat 50 times
            key code 125 -- down
            delay 0.1
        end repeat
        delay 0.5
    end repeat
end tell

See Events.h or my website for the key codes.

1
  • Alright so the delay one does not include the application in it. Also, the application requires a login at the beginning that I can do myself so is there a way I can activate the applescript program after I have already logged in so it doesn't have to activate PokeMMO it just like tells PokeMMO to press the keys? – Alex Kane Jul 8 '13 at 21:44
1
tell application "Your App Name Here"
    activate
    tell application "System Events"
        repeat 50 times
            key code 126
            -- up
        end repeat
        repeat 50 times
            key code 125
            -- down
        end repeat
    end tell
end tell
5
  • Alright so my application is PokeMMO and I got an AppleScript Error – Alex Kane Jul 8 '13 at 19:59
  • it says PokeMMO got an error: AppleEvent timed out – Alex Kane Jul 8 '13 at 20:00
  • That is exactly what happens – Alex Kane Jul 8 '13 at 20:03
  • Try adding the delay as @Lauri Ranta suggests. With the apps I've tried it with, I don't get a problem, but I've never worked with "PokeMMO". – Daniel Jul 8 '13 at 20:10
  • Alright so the delay one does not include the application in it. Also, the application requires a login at the beginning that I can do myself so is there a way I can activate the applescript program after I have already logged in so it doesn't have to activate PokeMMO it just like tells PokeMMO to press the keys? – Alex Kane Jul 8 '13 at 20:14

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .