Cesar Bielich
Cesar Bielich

Reputation: 4945

stop applescript script from running on keypress ESC

I have an applescript that sends keystrokes to TextEdit. I need to be able to stop the script at any time from simply pressing the ESC key. I tried some examples online I found but none seem to be working. I have no idea what I am doing lol. Any help would be awesome on this

This is the non working example

activate application "TextEdit"
repeat until (keys pressed) is {"esc"}
    set keys_pressed to keys pressed
    if keys_pressed is not {} then
        tell application "System Events"
            key code 18
        end tell
        delay (random number from 0.2 to 0.3)
        tell application "System Events"
            key code 19
        end tell
        delay (random number from 0.2 to 0.3)
    end if
end repeat

Upvotes: 3

Views: 1867

Answers (1)

YeaTheMen
YeaTheMen

Reputation: 1083

Im sorry but I don't think you can do this with just AppleScript, but I recommend Cocoa-AppleScript, Download Xcode and make a Cocoa AppleScript App, Cocoa AppleScript allows you to use Cocoa Windows linked to Applescript Code, you can then make a Menubar item to stop the repeating

Upvotes: 2

Related Questions