Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

stop applescript script from running on keypress ESC

Tags:

applescript

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
like image 273
Cesar Bielich Avatar asked Aug 17 '26 13:08

Cesar Bielich


1 Answers

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

like image 167
YeaTheMen Avatar answered Aug 21 '26 09:08

YeaTheMen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!