Sample Header Ad - 728x90

Is it possible to close a script with a keypress?

2 votes
1 answer
1494 views
In AutoHotKey, using the keyword "ExitApp" can allow the user to stop a script with a keypress. For example, Esc::ExitApp can stop a script by pressing "esc". Now, with a combination of do shell script (using a bash function like read) and on idle and then calling exit somehow, I thought this was possible in AppleScript. However, inside of an Automator function, you can't save an AppleScript as "stay open" - pasting the on idle thing underneath on run only loops through idle once without providing opportunities for listening for keypresses. Any ideas? Example: Let's say I have this script in an automator workflow:
on run {input, parameters}
	set i to 0
	 repeat while i < 100
       keystroke "a"
	   set i to i + 1
       delay 5
	 end repeat
end run
Asked by Aaron (33 rep)
May 7, 2021, 07:26 PM
Last activity: Jun 17, 2025, 02:03 PM