I see a lot of examples of AppleScript like this
tell application "TextEdit"
activate
tell application "System Events"
keystroke "s"
end tell
end tell
Expected result is that letter "s" will be typed into active document in TextEdit (assume there is at least one document window). But instead it always tries to save document (did it for changed document and open save dialog if it is a new). Same things happen for any key in any application at any time…
Does anybody know why System Events always send keystrokes like "… using {command down}"?
I run script from AppleScript Editor using Cmd+R, not by clicking Run button. Script begins executing immediately after I press key "R" down and that script sends keystroke "S" before I release Cmd or R. That's why sent keystroke "S" interprets by TextEdit with modifier Cmd.
The workaround is to click button Run or add delay at the beginning of script and use Cmd+R:
delay 0.2 -- 0.2 second delay is enough
tell application "TextEdit"
activate
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With