04/22 Safariの選択部分をGoogle Earthで開く
Webサイト上にGoogle Earthの位置情報ファイルkmlの内容が貼付けられているような場合に、それを選択しておくと、kmlファイルに書き出してGoogle Earthでオープンするというサンプルです。
| スクリプト名:Safariの選択部分をGoogle Earthで開く |
| tell application “Safari“ set a to do JavaScript “unescape(getSelection())” in document 1 end tell set a to a as Unicode text if a = “” then return set dPAth to path to desktop set tmpOut to (dPAth as string) & “temp.kml“ –write_to_file(a, tmpOut, false) of me saveInEncoding(a, tmpOut, “UTF8“) of me –UTF8 do shell script “sync“ tell application “Google Earth“ activate open file tmpOut end tell – 指定の文字エンコーディングでファイル書き出しon saveInEncoding(aText, aPath, aEncoding) set a to aText as Unicode text set aTmp to path to temporary items set outFile to (aTmp as string) & “temporary_utf16be_text_fromAS.txt“ write_to_file(a, outFile, false) of me do shell script “sync“ set outPPath to quoted form of POSIX path of (outFile as alias) set cnvPPath to quoted form of POSIX path of aPath try do shell script “iconv -f UTF-16BE -t ” & aEncoding & “ ” & outPPath & “ > ” & cnvPPath –do shell script “iconv -f UTF-16LE -t ” & aEncoding & ” ” & outPPath & ” > ” & cnvPPath end try do shell script “sync“ try do shell script “rm -f ” & outPPath end try end saveInEncoding – ファイルの追記ルーチン「write_to_file」–追記データ、追記対象ファイル、boolean(trueで追記) on write_to_file(this_data, target_file, append_data) try set the target_file to the target_file as text set the open_target_file to open for access file target_file with write permission if append_data is false then set eof of the open_target_file to 0 write this_data to the open_target_file starting at eof close access the open_target_file return true on error error_message try close access file target_file end try return error_message end try end write_to_file |
