Keystroke WITHOUT command key

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!

Thanks for your help!

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
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

The same thing happened.
The script hit the “O” in Koenig and went to the “Open file” window.

You are not facing the standard behavior and I have no idea of what may explain this odd one.

I assume that if the command key was depressed by something on your keyboard you would see that.

Yvan KOENIG running Yosemite 10.10.4 (VALLAURIS, France) jeudi 23 juillet 2015 19:22:59

Hey jkazz18,

Are you running your script by hitting Cmd-R?

If so it is this user-interaction that is at fault. Try running by clicking the {Run} button.

You can also put a small delay in front of the other code to give you time to get your fingers off the keyboard.

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.
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

Hey Yvan,

I get that crap too, but NOT if I click the {Run} button rather than hit Cmd-R.


MacBookPro6,1 · 2.66 GHz Intel Core i7 · 8GB RAM · OSX 10.10.4

tell application "TextEdit"
	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

Thank you. That works very nicely but, the “keystroke \r” should be entered as keystroke “\r” before compiling.

keystroke "\r"


Here I run the system in French.
After all, we may have different behaviors according to language in use.

Yvan KOENIG running Yosemite 10.10.4 in French (VALLAURIS, France) dimanche 26 juillet 2015 12:04:31