Get PC ASCII code for a character?

Hello,

I am working on a script that types characters into the DOSBox MS-DOS emulator. It works perfectly for ordinary ASCII characters (letters and numbers without accents or diacritics, etc.), and I am trying to make it work for accented characters.

One problem I have is that AppleScript returns the Mac ASCII numbers for characters, like this:

set charNum to ASCII number "é"
--> 142

But what I need is the PC ASCII number (which in this case is 130).

I thought I might be able to accomplish this by converting the string with textutil, but I haven’t been able to figure out an appropriate syntax. I would be grateful for any help with this.

change CP1252 (Windows character encoding) to the preferred encoding. I mean every windows encoding I know of has a quote as character 130 and é is character 233.

set theText to "é"
getCharValueForWindows(theText)

on getCharValueForWindows(char)
	return (do shell script "/bin/echo -n " & quoted form of character 1 of char & " | iconv -f UTF8 -t CP1252 | od -A n -t u1") as integer
end getCharValueForWindows

That is exactly the solution I was looking for! Thank you. For this to work correctly with DOSBox, the codepage needs to be one of the two common MS-DOS codepages, 437 (for North America) or 850 (for Europe),

So this code gives the result I need:

set theText to "é"
getCharValueForWindows(theText)

on getCharValueForWindows(char)
	return (do shell script "/bin/echo -n " & quoted form of character 1 of char & " | iconv -f UTF8 -t CP437 | od -A n -t u1") as integer
end getCharValueForWindows

I’ll adjust this so that “437” is the contents of a codePage variable, and that will cover the alternatives nicely.

Again, a thousand thanks for this.

Glad it worked because, like I said , I would never came up with Code Page 437 or 850 encodings. Everyday we learn a bit, thank you as well!.