System Events and Accented Characters?

What should I be doing to my strings so System Events will type international characters? Or, am I missing a setting somewhere’s?

I can type a tilde accented n by having Sys Events keystroke “n” using option down followed by a keystroke “n” but I really, really don’t want to have to detect these line by line and replace each character with two keystroke commands.

Best,

Can you explain a little more about what you mean?

Jon


[This script was automatically tagged for color coded syntax by Convert Script to Markup Code]

Hi Jon!

Sorry, I was sort of ambiguous.

I use System Events to typeset in apps that have less than useful dictionaries. Here’s an example of my problem. I’m using TextEdit for illustrational purposes only.

set theChars to (ASCII character 150) & " " & (ASCII character 132) & " " & (ASCII character 142) & " " & (ASCII character 131) & " " & (ASCII character 154) & " " & (ASCII character 133) as string

--"ñ Ñ  é  É  ö  Ö"

tell application "TextEdit"
	activate
	repeat with thisChar in (characters of theChars)
		my typeThis(thisChar)
	end repeat
end tell

on typeThis(aChar)
	tell application "System Events"
		keystroke aChar
	end tell
end typeThis

(*
For me, this types..

 ascii character 241 ascii character 209 ascii character 97 ascii character 201 ascii character 246 ascii character 214
--sorry - HTML is turned off or I would just include the html equivs.
--Ò — a … ˆ ÷
*)

I must confess total ignorance when it comes to Unicode, MacRoman etc.

Thanks Jon!

Yeah, I’m seeing the same results you are (using Mac OS X 10.3.9). Have to do some more testing…

Jon

Hi,

Getting the same here in Jaguar. Here’s a workaround using paste:

tell application “TextEdit”
activate
set the clipboard to (ASCII character 150)
end tell
tell application “System Events”
tell process “TextEdit”
keystroke “v” with command down
end tell
end tell

gl,

10.3.8 here.

I am able to paste, and can even type the characters if I ask System Events to type it just as I would:


tell application "TextEdit"
	activate
	tell application "System Events"
		keystroke "n" using option down
		keystroke "n"
		keystroke "n" using option down
		keystroke "n" using shift down
	end tell
end tell

The problem is, sometimes I have a list of items that numbers in the thousands that could potentially contain these characters and I’d rather not slow my script down to detect and handle these characters.

Best~

Hi Mytzlscript,

If you paste, then you don’t need to detect anything. Just set up your text before hand adn paste the whole text. Usually you need System Events only for non-scriptable apps. Here’s an example with Stickies:

set t to {“aàb”, “aáb”, “aäb”, “aâb”, “aãb”}
set d to AppleScript’s text item delimiters
set AppleScript’s text item delimiters to {return}
set new_t to t as string
set AppleScript’s text item delimiters to d
tell application “Stickies” to activate
tell application “System Events”
tell process “Stickies”
keystroke “n” with command down
set the clipboard to new_t
keystroke “v” with command down
end tell
end tell

You don’t need to detect anything.

If you’re just writing to a text file, then you can write to it with the standard additions read/write commands.

gl,

When I try kel’s script, it fails to compile with “command down” hilited. The message is: “Expected “into”, variable name, class name, other parameter name or property but found application constant or consideration.” Since I’ve never done this, I don’t know how to fix it.

Should be “using command down” - kel’s probably like me - used to Sändi’s Typetext. 8^)

Maybe I’ll just try pasting - I’m apprehensive because the app I’m doing it in is FreeHand and I’ve had bad experiences pasting text in FH. Plus, sometimes my list is fairly large.

Just irks me I can’t have System Events type these chars without simulating the extra keys.

Hi,

NovaScotian, sorry, they changed ‘with’ in Jaguar to ‘using’ in Panther.

Mytzlscript, I was getting bad results with ui scripting with both keystrokes and pasting. Usually when the macros work but you get bad results, You need to add delays. The script then takes longer and this is one of the bad things about ui scripting. Here’s an example when you try to paste items from a list one at a time in a repeat loop:

set t to {“aàb”, “aáb”, “aäb”, “aâb”, “aãb”}
tell application “Stickies” to activate
tell application “System Events”
tell process “Stickies”
keystroke “n” with command down
repeat with s in t
set the clipboard to s
keystroke “v” with command down
keystroke return
– delay 1
end repeat
end tell
end tell

Without the delay, I get the last string 5 times on my computer, but it’s ok with the delay. However, preparing the text before and pasting one time solves the glitch.

gl,