Keystroke not working correctly

When I run this this script:

tell application "TextEdit"
	activate
end tell
tell application "System Events"
	tell process "TextEdit"
		tell window 1
			keystroke "??    ??"
		end tell
	end tell
end tell

… the result is: “a�� ?��” and not: “��� ���”
Is this a bug or am I doing something wrong?

It looks like a bug to me but I don’t know much about unicode. Here is a workaround:

set the clipboard to "åäö ÅÄÖ"
tell application "TextEdit"
	activate
end tell
tell application "System Events"
	tell process "TextEdit"
		tell window 1
			keystroke "v" using command down
		end tell
	end tell
end tell

billearl,

Thank you. Your workaround works.

But I’m still wondering why my first attemp failed…

karipu

Hi,

Their ascii numbers are above 127. You need to do the exact keystrokes. For instance try this:

tell application "TextEdit" to activate
tell application "System Events"
	tell process "TextEdit"
		tell window 1
			keystroke "u" with option down
			keystroke "a"
		end tell
	end tell
end tell

gl,

kel,

Your script did’t work.

karipu

Hi,

That’s probably because of timing. If you put delays in there it should work all the time but will be slow. I would do it as in billearl post. Here I was just explaining why I think keystroking special characters does not work. What do you get when it doesn’t work? Try this:

tell application “TextEdit” to activate
tell application “System Events”
tell process “TextEdit”
tell window 1
keystroke “u” with option down
delay 1
keystroke “a”
end tell
end tell
end tell

gl,

I got this error message: Expected “into”, variable name, class name, other parameter name or property but found application constant or consideration.

…probably because TextEdit does not have a option down coman.

karipu

Hi karipu,

I think I remember somebody saying that Apple changed the wording on the ‘keystroke’ command. It was something like they change ‘with’ to something else I think. I’m starting to get mad again. Anyway, you’re probably running Panther right? It sounds like you got the error on that line. Sorry, I don’t have Panther and am waiting for Apple to get their act together ( hope it’s not forever and I might take up fishing again :-)). Somebody else can probably help you.

And, I forgot to say that you can look at the System Events dictionary to so what is the correct syntax for ‘keystroke’ in your version. I’m still assuming that you’re running Panther.

gl,

kel,

Yes.

Yes, it’s “using option down” instead of “with option down”

Thank you for participation. I will stick to the billearl’s solution, because it seems to be one you have to use when dealing with high ascii/unicode characters…

karipu

Glad you found the solution and thanks for writing back.

gl,