AppleScript and searching files

I have some files that have mixed Traditional Chinese and English text. I don’t want to go through the pain of manually selecting all the Traditional Chinese text and then going to TextEdit > Services > ChineseTextConverter > Convert Selected Traditional Chinese Text.

How can I write an AppleScript that opens the file, searches for Chinese Text, converts it, and then saves the changes?

What program are you using for the text and how is the Chinese text indicated? I’m not familiar with the conversion process or using Chinese text but there should be a way to do it if the tools are part of the Mac OS, the text editor is scriptable, and the text is set apart in a predictable way. Knowing the program that you are using and probably an example of the text would be a start figuring out if it is a feasible task for AppleScript to automate and how it could be accomplished.

I stated that it’s TextEdit (/Applications/TextEdit.app, the preinstalled text editor).

The Chinese text is, well, in Chinese. I was wondering if maybe it’s in a different encoding or something and if AppleScript could detect that. It’s not set apart in any predictable way, unfortunately.

The thing is that there are two types of Chinese writing: Traditional, which is used in small Chinese communities, and Simplified, which is used in mainland China. I prefer Simplified over Traditional writing.

Hi,

just an idea:
the chinese text is probably Unicode based, therefore you could identify the characters by a specified character id range.
This is quite easy in Leopard, because AppleScript 2.0 is fully Unicode based.
Parse the text character by character, separate the english and chinese text, paste the chinese in a new document and convert it.
A new document is necessary because you couldn’t select partial text in TextEdit via AppleScript.
Then join the parts again, if needed

I don’t have any idea how to activate the “Services” in AppleScript but I have something to share with you:

You don’t have to “selecting all the Traditional Chinese text and then going to TextEdit > Services > ChineseTextConverter > Convert Selected Traditional Chinese Text.”

Instead, you just need to select (don’t even have to open) the TextEdit file which contains Traditional Chinese text, then go to Finder > Services > ChineseTextConverter > Convert Selected Traditional Chinese File.

The system will automatically save another file which has converted the Traditional Chinese text in the file to Simplified Chinese text without touching those English text ““ at least it works in Tiger!

Of course, it will be even better if someone can advise on how to use AS to perform the task.