なんでか、以下のAppleEventの返り値はUTF16になっていて、これをhttpSocketクラスのGetメソッドに直接渡すとハングしてしまう。
ReplyStringで返ってきたものをTextConverterでUTF8に直してからGetに渡すとうまくいく。
くそー、足かせ一つ追加。ASCII文字列もエンコーディング関係あるんだっけ?
■Safariから最前面のウインドウで表示中のページのURLを取ってくる
Dim ae As AppleEvent
Dim obj As AppleEventObjectSpecifier
Dim c As TextConverter
obj=GetIndexedObjectDescriptor("docu", Nil , WinNum)
ae = NewAppleEvent("core","getd","sfri")
ae.ObjectSpecifierParam("----") = GetPropertyObjectDescriptor(obj, "pURL")
If ae.send() Then
c = GetTextConverter(Encodings.UTF16, Encodings.UTF8)
Return c.convert(ae.replyString)
End If
------------------------------
よーし、大物きたー。
■Safariのテキストエンコーディングのメニュー選択
Dim ae As AppleEvent
Dim objT, objU, objV, objW, objX, objY, objZ as AppleEventObjectSpecifier
Dim c As TextConverter
c = GetTextConverter(GuessJapaneseEncoding("テスト"), Encodings.MacJapanese)
//SafariをActivate
ae = NewAppleEvent("misc","actv","sfri")
if ae.send() then
end if
//メニューを選ぶ
ae = NewAppleEvent("prcs", "clic", "sevs")
objZ = GetNamedObjectDescriptor("pcap", Nil, "Safari")
objY = GetIndexedObjectDescriptor("mbar", objZ, 1)
objX = GetNamedObjectDescriptor("mbri", objY, c.convert("表示"))
objW = GetNamedObjectDescriptor("menE", objX, c.convert("表示"))
objV = GetNamedObjectDescriptor("menI", objW, c.convert("テキストエンコーディング"))
objU = GetNamedObjectDescriptor("menE", objV, c.convert("テキストエンコーディング"))
objT = GetNamedObjectDescriptor("menI", objU, c.convert("日本語(ISO 2022-JP)"))
ae.ObjectSpecifierParam("----") = objT
If ae.send() then
end if
GetIndexedObjectDescriptorで表現する場合は、ObjectDescriptorの部分が次のようになる。
objZ = GetNamedObjectDescriptor("pcap", Nil, "Safari")
objY = GetIndexedObjectDescriptor("mbar", objZ, 1)
objX = GetIndexedObjectDescriptor("mbri", objY, 5)
objW = GetIndexedObjectDescriptor("menE", objX, 1)
objV = GetIndexedObjectDescriptor("menI", objW, 14)
objU = GetIndexedObjectDescriptor("menE", objV, 1)
objT = GetIndexedObjectDescriptor("menI", objU, 5)
AppleEventに固執するのはよくないけど、あのベンチ結果を目の当たりにすると粘りたくもなる。
Recent Comments