« ドリームページ・プラス | トップページ | XPSReader »

[AppleScripts]GoogleMapのURLからBridge用のGPS用の値を作る【v3一部修正】

GoogleマップのURLから
GPS値を取得して
XMPファイルを作成→AdobeBridgeでメタを書き込み出来る
そんなAppleScriptですが
年末だって〜のに少し時間が出来たので
大幅に直しを入れました。
致命的だったゼロサプレスの不具合をようやく修正しました
1:ファイルの作成方法を大幅に変更しました
2:東経西経 北緯南緯に対応しました
3:URLデコード部分とawk文を修正しました
4:また著作情報をあらかじめ設定出来るようにしました

一部不具合があって
ファイルの書き込みが上手く行かない事がありますが
まぁ普通に使う分には問題ないので
そのままにしました
(どうしても日本語ファイル名の時に上手く行かない事がある)

(*
GoogleMap2Bridgev3.scpt
致命的な0サプレス処理の不具合を訂正した
東経西経 北緯南緯に対応した
URLデコード部分とawk文を修正した
また著作情報をあらかじめ設定出来るようにした
GoogleMapURLから東経北緯を取得して
XMPファイルを作成します
Adobe Bridge GPSタブで写真に撮影場所として追加する事が出来ます
詳しくは
https://force4u.cocolog-nifty.com/skywalker/2013/02/applescriptsg-1.html
ご覧下さい
*)

-----------設定項目
(*
True 著作を有している
False 著作フリー又は無し
*)
set theRights to "True" as «class utf8»
-----著作情報の掲載してあるWEBページ
set theWebStatement to "http://creativecommons.org/licenses/by-nc-nd/4.0/deed.ja" as «class utf8»
------著作権情報
set theDcRights to "Creative Commons Attribution-NonCommercial-NoDerivatives 4.0" as «class utf8»
-----使用にともなう制限について
set theUsageTerms to "商用利用はお問い合わせ下さい" as «class utf8»
-----作成者WEB
set theCiUrlWork to "https://force4u.cocolog-nifty.com/" as «class utf8»

-----------------------------ここから本処理
--------------デフォルトアンサー用に昭和基地のURL
set theOrgGoogleMapUrl to "https://maps.google.com/maps?q=%E6%98%AD%E5%92%8C%E5%9F%BA%E5%9C%B0&ie=UTF8&ll=-69.004783,39.581938&spn=0.015499,0.047293&num=20&safe=off&hq=%E6%98%AD%E5%92%8C%E5%9F%BA%E5%9C%B0&radius=15000&t=h&z=15" as «class utf8»
--------------URLをペーストするダイアログを出す
display dialog "GoogleMapURLをペーストしてください" default answer the theOrgGoogleMapUrl with icon 1 with title "GoogleMapURLをペーストしてください" default button 1
--------------リザルトをリスト形式で格納
copy the result as list to {the theOrgGoogleMapUrl, BottPressNo}
--------------東経と北緯のLLの値を取り出す
set theAwkComLL to "echo " & quoted form of theOrgGoogleMapUrl & "| awk -F \"ll=\" '{print($2)}' |awk -F \"&\" '{print($1)}' " as «class utf8»
set theAwkComQ to "echo " & quoted form of theOrgGoogleMapUrl & "| awk -F \"q=\" '{print($2)}' |awk -F \"&\" '{print($1)}' " as «class utf8»
--------------エラー制御
try
set theGoogleLlNo to do shell script theAwkComLL as «class utf8»
if theGoogleLlNo is "" then
display alert "GPSデータを取得出来ませんでした"
end if
on error
set theGoogleLlNo to do shell script theAwkComQ as «class utf8»
if theGoogleLlNo is "" then
display alert "GPSデータを取得出来ませんでした"
end if
end try
--------------llの値をリスト形式に整形
set AppleScript's text item delimiters to {","}
set theGoogleLlNoList to every text item of theGoogleLlNo as list
set numNorS to ""
set numEorW to ""
--------------Latitude60進数の処理
set theLatitude to item 1 of theGoogleLlNoList as string
if theLatitude contains "-" then
set theLatitude to doReplace(theLatitude, "-", "")
set numNorS to 1
end if
set theIntegerLatitude to theLatitude div 1 as string
set theLatitude to (text 2 thru 8 of (((theLatitude mod 1) as string) & "000000") as string)
set theLatitude to theIntegerLatitude & theLatitude
set theDecimalLatitudeA to (((theLatitude as number) - (theIntegerLatitude as number)) as number) * 60
set theIntegerDecimalLatitudeA to theDecimalLatitudeA div 1 as integer
set theDecimalLatitudeB to (((theDecimalLatitudeA as number) - (theIntegerDecimalLatitudeA as number)) as number) * 100 as integer
---修正されたゼロサプレス処理
set theIntegerLatitude to doZeroSuppress(theIntegerLatitude)
set theIntegerDecimalLatitudeA to doZeroSuppress(theIntegerDecimalLatitudeA)
set theDecimalLatitudeB to doZeroSuppress(theDecimalLatitudeB)
if numNorS is 1 then
set theLatitude to theIntegerLatitude & "," & theIntegerDecimalLatitudeA & "." & theDecimalLatitudeB & "S" as «class utf8»
else
set theLatitude to theIntegerLatitude & "," & theIntegerDecimalLatitudeA & "." & theDecimalLatitudeB & "N" as «class utf8»
end if
--------------Longitude60進数の処理
set theLongitude to item 2 of theGoogleLlNoList as string
if theLongitude contains "-" then
set theLongitude to doReplace(theLongitude, "-", "")
set numEorW to 1
end if
set theIntegerLongitude to theLongitude div 1 as string
set theLongitude to (text 2 thru 8 of (((theLongitude mod 1) as string) & "000000") as string)
set theLongitude to theIntegerLongitude & theLongitude
set theDecimalLongitudeA to (((theLongitude as number) - (theIntegerLongitude as number)) as number) * 60
set theIntegerDecimalLongitudeA to theDecimalLongitudeA div 1 as integer
set theDecimalLongitudeB to (((theDecimalLongitudeA as number) - (theIntegerDecimalLongitudeA as number)) as number) * 100 as integer
---修正されたゼロサプレス処理
set theIntegerLongitude to doZeroSuppress(theIntegerLongitude)
set theIntegerDecimalLongitudeA to doZeroSuppress(theIntegerDecimalLongitudeA)
set theDecimalLongitudeB to doZeroSuppress(theDecimalLongitudeB)
if numEorW is 1 then
set theLongitude to theIntegerLongitude & "," & theIntegerDecimalLongitudeA & "." & theDecimalLongitudeB & "W" as «class utf8»
else
set theLongitude to theIntegerLongitude & "," & theIntegerDecimalLongitudeA & "." & theDecimalLongitudeB & "E" as «class utf8»
end if
--------------ダイアログ用に改行を入れて整形しておく
set tneAns to theLatitude & "\n" & theLongitude
--------------出来上がりデータをダイアログで表示
display dialog "Bridge用のGPSの値です" default answer the tneAns with icon 1 with title "Adobe Bridge GPS" default button 1 buttons {"XMPファイルも作る", " 終了 "}
--------------XMPファイルも作る場合の始まり
if button returned of the result is "XMPファイルも作る" then
--------------XMPファイルとBridgeの関連づけの確認
do shell script "date > /tmp/ApplicationChk.xmp"
set theTmpXmpFile to (the path to startup disk as string) & "tmp:ApplicationChk.xmp" as alias
set theFileInfo to default application of (info for theTmpXmpFile) as string
--------------Bridgeが未インストールの可能性のエラー制御
if (theFileInfo contains "Bridge") is false then
display alert "XMPファイルがAdobe Bridgeに関連づけられていません"
--------------XMPファイル作成の本処理のはじまり
else if (theFileInfo contains "Bridge") is true then
--------------XMPファイルの保存先ディレクトリを取得
set theSaveXmpPath to (the path to application support from user domain as text) & "Adobe:XMP:Metadata Templates:"
--------------東経と北緯データの再取得(ここは別な方法があったかな)
set theGoogleLlNoQ to do shell script theAwkComQ as «class utf8»

set theDateTime to (do shell script "date +'%Y%m%d_%H%M%S'" as string)
--------------qの値=検索語句の有無
if theGoogleLlNoQ is "" then
--------------qの値=検索語句が無い場合はファイル名を日付にするため日付の処理
set theXmpFileName to (theLatitude & "_" & theLongitude & "_" & theDateTime & ".xmp") as «class utf8»
set theXmpFileName to my doReplace(theXmpFileName, ",", ".") as «class utf8»
set theGooogleMapQ to theLatitude & " " & theLongitude
else
--------------検索語句がある場合はデコードしてファイル名にする
set theGooogleMapQ to my doDecodeURL(theGoogleLlNoQ) as «class utf8»
set theXmpFileName to (theGooogleMapQ & ".xmp") as «class utf8»
end if
-----------------------------------------------ここからXMPファイルの作成
-------------XMPファイルの最初の1行
set theXMPline to "<?xpacket begin=\"\" id=\"W5M0MpCehiHzreSzNTczkc9d\"?>\n" as «class utf8»
-------------XMPファイル
set theXMPline to theXMPline & "<x:xmpmeta xmlns:x=\"adobe:ns:meta/\" x:xmptk=\"Adobe XMP Core 5.3-c011 66.145661, 2012/02/06-14:56:27\">\n" as «class utf8»
-------------宣言
set theXMPline to theXMPline & "<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">\n" as «class utf8»
set theXMPline to theXMPline & "<rdf:Description rdf:about=\"\"\n" as «class utf8»
set theXMPline to theXMPline & " xmlns:xmpRights=\"http://ns.adobe.com/xap/1.0/rights/\"\n" as «class utf8»
set theXMPline to theXMPline & " xmpRights:WebStatement=\"" & theWebStatement & "\"\n" as «class utf8»
set theXMPline to theXMPline & " xmpRights:Marked=\"" & theRights & "\"\n" as «class utf8»
-------------Description
set theXMPline to theXMPline & " xmlns:dc=\"http://purl.org/dc/elements/1.1/\"\n" as «class utf8»
set theXMPline to theXMPline & " xmlns:photoshop=\"http://ns.adobe.com/photoshop/1.0/\"\n" as «class utf8»
set theXMPline to theXMPline & " xmlns:Iptc4xmpCore=\"http://iptc.org/std/Iptc4xmpCore/1.0/xmlns/\"\n" as «class utf8»
set theXMPline to theXMPline & " xmlns:Iptc4xmpExt=\"http://iptc.org/std/Iptc4xmpExt/2008-02-29/\"\n" as «class utf8»
set theXMPline to theXMPline & " xmlns:exif=\"http://ns.adobe.com/exif/1.0/\"\n" as «class utf8»
-------------photoshop
set theXMPline to theXMPline & " photoshop:Instructions=\"" & theGooogleMapQ & "\"\n" as «class utf8»
-------------Iptc4xmpCore
set theXMPline to theXMPline & " Iptc4xmpCore:Location=\"" & theGooogleMapQ & "\"\n" as «class utf8»
-------------exif:
set theXMPline to theXMPline & " exif:GPSLatitude=\"" & theLatitude & "\"\n" as «class utf8»
set theXMPline to theXMPline & " exif:GPSProcessingMethod=\"MANUAL\"\n" as «class utf8»
set theXMPline to theXMPline & " exif:GPSAltitude=\"0.00 m\"\n" as «class utf8»
set theXMPline to theXMPline & " exif:GPSLongitude=\"" & theLongitude & "\">\n" as «class utf8»
-------------dc
set theXMPline to theXMPline & " <dc:subject>\n" as «class utf8»
set theXMPline to theXMPline & " <rdf:Bag>\n" as «class utf8»
set theXMPline to theXMPline & " <rdf:li>" & theGooogleMapQ & "</rdf:li>\n" as «class utf8»
set theXMPline to theXMPline & " </rdf:Bag>\n" as «class utf8»
set theXMPline to theXMPline & " </dc:subject>\n" as «class utf8»
-------------Iptc4xmpExt
set theXMPline to theXMPline & " <Iptc4xmpExt:LocationShown>\n" as «class utf8»
set theXMPline to theXMPline & " <rdf:Bag>\n" as «class utf8»
set theXMPline to theXMPline & " <rdf:li\n" as «class utf8»
set theXMPline to theXMPline & " Iptc4xmpExt:Sublocation=\"" & theGooogleMapQ & "\"/>\n" as «class utf8»
set theXMPline to theXMPline & " </rdf:Bag>\n" as «class utf8»
set theXMPline to theXMPline & " </Iptc4xmpExt:LocationShown>\n" as «class utf8»
-------------著作情報...
set theXMPline to theXMPline & "<dc:rights>\n" as «class utf8»
set theXMPline to theXMPline & "<rdf:Alt>\n" as «class utf8»
set theXMPline to theXMPline & "<rdf:li xml:lang=\"x-default\">" & theDcRights & "</rdf:li>\n" as «class utf8»
set theXMPline to theXMPline & "</rdf:Alt>\n" as «class utf8»
set theXMPline to theXMPline & "</dc:rights>\n" as «class utf8»
set theXMPline to theXMPline & "<xmpRights:UsageTerms>\n" as «class utf8»
set theXMPline to theXMPline & "<rdf:Alt>\n" as «class utf8»
set theXMPline to theXMPline & "<rdf:li xml:lang=\"x-default\">" & theUsageTerms & "</rdf:li>\n" as «class utf8»
set theXMPline to theXMPline & "</rdf:Alt>\n" as «class utf8»
set theXMPline to theXMPline & "</xmpRights:UsageTerms>\n" as «class utf8»
----------ITPCCORE
set theXMPline to theXMPline & "<Iptc4xmpCore:CreatorContactInfo\n" as «class utf8»
set theXMPline to theXMPline & " Iptc4xmpCore:CiUrlWork=\"" & theCiUrlWork & "\"/>\n" as «class utf8»
-------------XMPの終了
set theXMPline to theXMPline & " </rdf:Description>\n" as «class utf8»
set theXMPline to theXMPline & " </rdf:RDF>\n" as «class utf8»
set theXMPline to theXMPline & "</x:xmpmeta>\n" as «class utf8»
set theXMPline to theXMPline & "<?xpacket end=\"w\"?>\n" as «class utf8»
--------------ファイルを作る
tell application "Finder"
try
make new file at (theSaveXmpPath) with properties {name:theXmpFileName}
set aliasXmlFileAlias to (theSaveXmpPath & theXmpFileName) as alias
set theXmlFileAlias to aliasXmlFileAlias as text
set numFileChk to 1
on error
-----すでにファイルがあった場合に別名にする
make new file at (theSaveXmpPath) with properties {name:(theDateTime & "_" & theXmpFileName)}
set aliasXmlFileAlias to (theSaveXmpPath & (theDateTime & "_" & theXmpFileName)) as alias
set theXmlFileAlias to aliasXmlFileAlias as text
set numFileChk to 2
try
delete (theSaveXmpPath & theXmpFileName) as alias
end try
end try
end tell
-----------検索語句がファイル名の場合の処理
if numFileChk is 1 then
try
set theData to open for access file theXmlFileAlias with write permission
write theXMPline to theData as «class utf8»
close theData
on error
------書き込みに失敗したらシェルでの書き込みを試す
do shell script "echo " & quoted form of theXMPline & " >> " & quoted form of (POSIX path of theXmlFileAlias)
end try
---------日付け付きのファイル名に鳴った場合
else if numFileChk is 2 then
set theData to open for access file theXmlFileAlias with write permission
write theXMPline to theData as «class utf8»
close theData
end if
-------------出来上がったXMPファイルにラベルを塗って保存したフォルダを開く
tell application "Finder"

set file type of aliasXmlFileAlias to "XML "
set creator type of aliasXmlFileAlias to "Brdg"
set label index of aliasXmlFileAlias to 5
open folder theSaveXmpPath
activate
end tell
end if
else if button returned of the result is "終了" then
end if





--------------------------------------------------#ここからサブルーチン

to doReplace(theText, orgStr, newStr)
set oldDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to orgStr
set tmpList to every text item of theText
set AppleScript's text item delimiters to newStr
set tmpStr to tmpList as text
set AppleScript's text item delimiters to oldDelim
return tmpStr
end doReplace

on doDecodeURL(theUrlEncodeText)
set theScpt to ("echo \"<?php print(urldecode('" & theUrlEncodeText & "'));?>\" | php")
return do shell script theScpt as «class utf8»
end doDecodeURL


to doZeroSuppress(n)
if n < 10 then
return "0" & n
else
return n as text
end if
end doZeroSuppress


「GoogleMap2Bridgev3.scpt.rtf」をダウンロード

「GoogleMap2Bridgev3.scpt.zip」をダウンロード


使い方 メモ

GoogleMapで検索して
場所が決まったら
右クリックして「ここを中央にする」を実行してください
20131218_205314

中央に移動が終了したら
リンクを取得します
20131218_205344

|

« ドリームページ・プラス | トップページ | XPSReader »

AdobeBridge」カテゴリの記事