Translate via Google from English to Korean and Back


The following script should check if the selected text in Safari is English. If so, it should open|ko| with the text translated to Korean. If it’s not English, it should open|en| and translate the text to English. But it doesn’t! And I can’t understand why…

tell application "Safari"
	set transText to do JavaScript "getSelection();" in document 1
	set theChars to the characters of transText
	if theChars contains "a" or "e" or "i" or "o" or "u" then
		open location "|ko|" & transText
		open location "|en|" & transText
	end if
end tell

Any insight is greatly appreciated!

If you need some Korean text to experiment on, try한글&ie=UTF-8&oe=UTF-8.

I’m thinking it has something to do with Safari’s cache of saved sites, insofar as the script will open whatever translate direction that I used last (i.e., Eng>>Kor or Kor>>Eng). How can I force it to open the correct site?

Nice one :slight_smile: !
But what do you mean with "doesn’t work! ?
Here, Safari 3.1.2 on Tiger 4.11, it works like (I suppose) it should…


Browser: Safari 525.22
Operating System: Mac OS X (10.4)