I’m trying to run a very simple repeat script which hits the return key every x seconds.
However the editor seems to run the keystroke with the command key down no matter what.
When I say
tell application “System Events”
keystroke return
I get cmd + return
When I say
tell application “System Events”
keystroke “return”
I get cmd + R, E, T, U, R, N. (In safari, for example, this reloads a page, then opens a new tab, reloads the tab, then opens a new window)
What am I doing wrong! I’m (obviously) a beginner and just trying to get into the applescripting game!
It would be useful to know the exact code which you try to use.
On my machine, keystroke is accompanied by a modifier ONLY when I explicitly ask it to do.
Just to check I ran:
tell application "System Events" to tell process "TextEdit"
set frontmost to true
keystroke "KÅ’NIG Yvan"
keystroke return
keystroke "KOENIG Yvan"
end tell
and I got
KÅ’NIG Yvan
KOENIG Yvan
in the TextEdit document.
Not sure that you will get the same behavior on a system running in English for the first line (Å’).
Yvan KOENIG (VALLAURIS, France) jeudi 23 juillet 2015 18:14:20
Hello Chris
Thanks for the explanation but I’m not sure that it apply to the OP’s case.
I got the described odd behavior with
tell application "System Events"
keystroke "return"
end tell
But I didn’t got it with my sample script which behaved oddly too on the OP’s machine. kazz18
2015-07-23 11:55:38 am
The same thing happened.
The script hit the “O” in Koenig and went to the “Open file” window.
So I’m always scrapping my head.
Yvan KOENIG (VALLAURIS, France) samedi 25 juillet 2015 17:25:25
tell application "TextEdit"
activate
set frontmost to true
delay 1 -- Give the Text Edit window time to come up
tell application "System Events"
keystroke "Frozen"
keystroke "
"
-- That line above is entered as "keystroke \r" the editor changes it to an actual return when the script is compiled.
keystroke "pizza."
end tell
end tell
return