开发者

Get window title with AppleScript in Unicode

I've stuck with the following p开发者_如何转开发roblem: I have a script which is retrieving title form the Firefox window:

tell application "Firefox"
   if the (count of windows) is not 0 then
       set window_name to name of front window
   end if
end tell

It works well as long as the title contains only English characters but when title contains some non-ASCII characters(Cyrillic in my case) it produces some utf-8 garbage. I've analyzed this garbage a bit and it seems that my Cyrillic character is converted to the Utf-8 without any concerning about codepage i.e instead of using Cyrillic codepage for conversion it uses non codepages at all and I have utf-8 text with characters different from those in the window title.

My question is: How can I retrieved the window title in utf-8 directly without any conversion? I can achieve this goal by using AXAPI but I want to achieve this by AppleScript because AXAPI needs some option turned on in the system.

UPD: It works fine in the AppleScript Editor. But I'm compiling it through the C++ code via OSACompile->OSAExecute->OSADisplay I don't know the guts of the AppleScript Editor so maybe it has some inside information about how to encode the characters


I've found the answer when wrote update. Sometimes it is good to ask a question for better it understanding :) So for the future searchers: If you want to use unicode result of the script execution you should provide typeUnicodeText to the OSADisplay then you will have result in the UTF-16LE in the result AEDesc

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜