repeat until keystroke is pressed

Is there a way to repeat until any keystroke is pressed.
I want to have an alarm go off when a copy is finished and stop when I hit any key.
Or maybe it could involve a dialog when the copy is complete, e.g. “hit enter to cancel alarm”

so far I have

tell application "Finder"
	copy file TheFile to folder TheFolder
	tell application "System Events"
		repeat
			say "copy complete"
			delay 5
		end repeat
	end tell
end tell

where thefile and theFolder will be defined with a dialog

so at the moment it repeats 5 times but Id like it to keep repeating until i press a key.
in case I have gone out of the room for 10 mins and miss the 5 times repeat al together

any thoughts would be greatly appreciated

Thanks in advance
L

Perform a a test inside the loop:

repeat
	-- lots of useful code here
	-- then test some condition:
	if some_test_you_can - think_of is true then exit repeat
end repeat

Stopping some sound playback is hard, I think. AppleScript cannot play sound and look for a keypress at the same time.

If AppleScript cannot perform both in one script, how about a separate AppleScript app to play the sound that is stopped by the script looking for the key press.

Thanks guys,
alastor933
I could try having a dialog open and ask to press enter if you want to cancel the alarm but that would stop the repeat until some action was take with the dialog

Is there anyway applescript can listen for a keystroke without interrupting a loop?

Adam Bell
interesting idea. is there somewhere you can recommend me to read up on how you can get one applescript to interact with another applescript while its running?
or have I miss understood what you are saying…

thanks again

StefanK’s checkModifierKeys worked well under Tiger. With a little modification, it’s got some deprecated calls, the CLI can be made to run under Snow-leopard through Mavericks.

Just FYI, StefanK’s checkModifierKeys is still working great in 10.14.3!

Thank you, yet again, Stefan!!

Blessings!

Richard Fairbanks