使用 AppleScript 获取 Unicode 格式的窗口标题
我一直遇到以下问题: 我有一个从 Firefox 窗口检索标题的脚本:
tell application "Firefox"
if the (count of windows) is not 0 then
set window_name to name of front window
end if
end tell
只要标题仅包含英文字符,它就可以正常工作,但是当标题包含一些非 ASCII 字符(在我的例子中是西里尔字母)时,它会产生一些 utf-8 垃圾。我对这个垃圾进行了一些分析,似乎我的西里尔字符被转换为 Utf-8,而不用担心代码页,即不是使用西里尔代码页进行转换,它根本使用非代码页,并且我有带有字符的 utf-8 文本与窗口标题中的不同。
我的问题是:如何直接检索 utf-8 格式的窗口标题而不进行任何转换? 我可以通过使用 AXAPI 来实现此目标,但我想通过 AppleScript 来实现此目标,因为 AXAPI 需要在系统中打开一些选项。
UPD: 它在 AppleScript 编辑器中运行良好。但我通过 OSACompile->OSAExecute->OSADisplay 通过 C++ 代码编译它 我不知道 AppleScript 编辑器的内部结构,所以也许它有一些关于如何对字符进行编码的内部信息
I've stuck with the following problem:
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我在写更新时找到了答案。有时提出问题可以更好地理解它:)
因此,对于未来的搜索者:如果您想使用脚本执行的 unicode 结果,您应该向 OSADisplay 提供 typeUnicodeText,然后您将在 UTF-16LE 中得到结果结果AE描述
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