« [AppleScript]quicklookを再起動する | トップページ | [AppleScript]Flash Player をアンインストール »

[AppleScripts]GoogleMapのURLからBridge用のGPS用の値を作る【最終回】


こちら
http://force4u.cocolog-nifty.com/skywalker/2013/12/applescriptsgoo.html に
修正版を公開しました

----------

GoogleMapのURLからGPSデータを取得して
XMPファイルにかき出し
Adobe Bridgeで適応するって流れ用です。

制限事項があります。
必ず地図のセンタリングを行なってからURLを取得してください

20130209_120124

URLは
この場所のを使います


20130209_120633


出来上がったXMPファイルは
Bridgeで適応します

20130209_121551


高度については処理していませんので
高度は0になります

Website_image20130209_120857


  


--------------デフォルトアンサー用に東京タワーのURL
set theOrgGoogleMapUrl to "https://maps.google.com/maps?q=%E6%9D%B1%E4%BA%AC%E3%82%BF%E3%83%AF%E3%83%BC&hl=en&ie=UTF8&ll=35.658595,139.745439" as text

--------------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 text
set theAwkComQ to "echo " & quoted form of theOrgGoogleMapUrl & "| awk -F \"q=\" '{print($2)}' |awk -F \"&\" '{print($1)}' " as text

--------------エラー制御
try
set theGoogleLlNo to do shell script theAwkComLL as text
if theGoogleLlNo is "" then
display alert "GPSデータを取得出来ませんでした"
end if
on error
set theGoogleLlNo to do shell script theAwkComQ as text
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
--------------Latitude60進数の処理
set theLatitude to item 1 of theGoogleLlNoList as text
set theIntegerLatitude to theLatitude div 1 as text
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 text
set theDecimalLatitudeB to (((theDecimalLatitudeA as number) - (theIntegerDecimalLatitudeA as number)) as number) * 100 as integer
set theLatitude to theIntegerLatitude & "," & theIntegerDecimalLatitudeA & "." & theDecimalLatitudeB & "N" as text
--------------Longitude60進数の処理
set theLongitude to item 2 of theGoogleLlNoList as text
set theIntegerLongitude to theLongitude div 1 as text
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 text
set theDecimalLongitudeB to (((theDecimalLongitudeA as number) - (theIntegerDecimalLongitudeA as number)) as number) * 100 as integer
set theLongitude to theIntegerLongitude & "," & theIntegerDecimalLongitudeA & "." & theDecimalLongitudeB & "E" as text
--------------ダイアログ用に改行を入れて整形しておく
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 text
--------------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 text
--------------qの値=検索語句の有無
if theGoogleLlNoQ is "" then
--------------qの値=検索語句が無い場合はファイル名を日付にするため日付の処理
set theDateTime to (do shell script "date +'%Y%m%d_%H%M%S'" as string)
set theXmpFileName to (theLatitude & "_" & theLongitude & "_" & theDateTime & ".xmp") as text
set theXmpFileName to my replace(theXmpFileName, ",", ".") as text
set theGooogleMapQ to theLatitude & " " & theLongitude
else
--------------検索語句がある場合はデコードしてファイル名にする
set theGooogleMapQ to my decodeURL(theGoogleLlNoQ)
set theXmpFileName to (theGooogleMapQ & ".xmp") as text
end if
--------------XMPファイルの保存先を作成
set theDistPathXmpFile to (POSIX path of ((theSaveXmpPath & theXmpFileName) as text)) as text
--------------ファイルを作っておく(既に同名がある場合は上書きになる)
do shell script "touch " & quoted form of theDistPathXmpFile
--------------パスを格納
set theDistFileXmpFile to (POSIX file theDistPathXmpFile) as alias
-----------------------------------------------ここからXMPファイルの作成
-------------XMPファイルの最初の1行
set theXMPline to "<?xpacket begin=\"\" id=\"W5M0MpCehiHzreSzNTczkc9d\"?>"
do shell script "echo " & quoted form of theXMPline & " > " & quoted form of theDistPathXmpFile
-------------XMPファイル
set theXMPline to "<x:xmpmeta xmlns:x=\"adobe:ns:meta/\" x:xmptk=\"Adobe XMP Core 5.3-c011 66.145661, 2012/02/06-14:56:27\">"
do shell script "echo " & quoted form of theXMPline & " >> " & quoted form of theDistPathXmpFile
-------------宣言
set theXMPline to "<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">"
do shell script "echo " & quoted form of theXMPline & " >> " & quoted form of theDistPathXmpFile
set theXMPline to "<rdf:Description rdf:about=\"\""
do shell script "echo " & quoted form of theXMPline & " >> " & quoted form of theDistPathXmpFile
set theXMPline to " xmlns:dc=\"http://purl.org/dc/elements/1.1/\""
do shell script "echo " & quoted form of theXMPline & " >> " & quoted form of theDistPathXmpFile
set theXMPline to " xmlns:photoshop=\"http://ns.adobe.com/photoshop/1.0/\""
do shell script "echo " & quoted form of theXMPline & " >> " & quoted form of theDistPathXmpFile
set theXMPline to " xmlns:Iptc4xmpCore=\"http://iptc.org/std/Iptc4xmpCore/1.0/xmlns/\""
do shell script "echo " & quoted form of theXMPline & " >> " & quoted form of theDistPathXmpFile
set theXMPline to " xmlns:Iptc4xmpExt=\"http://iptc.org/std/Iptc4xmpExt/2008-02-29/\""
do shell script "echo " & quoted form of theXMPline & " >> " & quoted form of theDistPathXmpFile
set theXMPline to " xmlns:exif=\"http://ns.adobe.com/exif/1.0/\""
do shell script "echo " & quoted form of theXMPline & " >> " & quoted form of theDistPathXmpFile
-------------photoshop
set theXMPline to " photoshop:Instructions=\"" & theGooogleMapQ & "\""
do shell script "echo " & quoted form of theXMPline & " >> " & quoted form of theDistPathXmpFile
-------------Iptc4xmpCore
set theXMPline to " Iptc4xmpCore:Location=\"" & theGooogleMapQ & "\""
do shell script "echo " & quoted form of theXMPline & " >> " & quoted form of theDistPathXmpFile
-------------exif:
set theXMPline to " exif:GPSLatitude=\"" & theLatitude & "\""
do shell script "echo " & quoted form of theXMPline & " >> " & quoted form of theDistPathXmpFile
set theXMPline to " exif:GPSProcessingMethod=\"MANUAL\""
do shell script "echo " & quoted form of theXMPline & " >> " & quoted form of theDistPathXmpFile
set theXMPline to " exif:GPSAltitude=\"0.00 m\""
do shell script "echo " & quoted form of theXMPline & " >> " & quoted form of theDistPathXmpFile
set theXMPline to " exif:GPSLongitude=\"" & theLongitude & "\">"
do shell script "echo " & quoted form of theXMPline & " >> " & quoted form of theDistPathXmpFile
-------------dc
set theXMPline to " <dc:subject>"
do shell script "echo " & quoted form of theXMPline & " >> " & quoted form of theDistPathXmpFile
set theXMPline to " <rdf:Bag>"
do shell script "echo " & quoted form of theXMPline & " >> " & quoted form of theDistPathXmpFile
set theXMPline to " <rdf:li>" & theGooogleMapQ & "</rdf:li>"
do shell script "echo " & quoted form of theXMPline & " >> " & quoted form of theDistPathXmpFile
set theXMPline to " </rdf:Bag>"
do shell script "echo " & quoted form of theXMPline & " >> " & quoted form of theDistPathXmpFile
set theXMPline to " </dc:subject>"
do shell script "echo " & quoted form of theXMPline & " >> " & quoted form of theDistPathXmpFile
-------------Iptc4xmpExt
set theXMPline to " <Iptc4xmpExt:LocationShown>"
do shell script "echo " & quoted form of theXMPline & " >> " & quoted form of theDistPathXmpFile
set theXMPline to " <rdf:Bag>"
do shell script "echo " & quoted form of theXMPline & " >> " & quoted form of theDistPathXmpFile
set theXMPline to " <rdf:li"
do shell script "echo " & quoted form of theXMPline & " >> " & quoted form of theDistPathXmpFile
set theXMPline to " Iptc4xmpExt:Sublocation=\"" & theGooogleMapQ & "\"/>"
do shell script "echo " & quoted form of theXMPline & " >> " & quoted form of theDistPathXmpFile
set theXMPline to " </rdf:Bag>"
do shell script "echo " & quoted form of theXMPline & " >> " & quoted form of theDistPathXmpFile
set theXMPline to " </Iptc4xmpExt:LocationShown>"
do shell script "echo " & quoted form of theXMPline & " >> " & quoted form of theDistPathXmpFile
-------------XMPの終了
set theXMPline to " </rdf:Description>"
do shell script "echo " & quoted form of theXMPline & " >> " & quoted form of theDistPathXmpFile
set theXMPline to " </rdf:RDF>"
do shell script "echo " & quoted form of theXMPline & " >> " & quoted form of theDistPathXmpFile
set theXMPline to "</x:xmpmeta>"
do shell script "echo " & quoted form of theXMPline & " >> " & quoted form of theDistPathXmpFile
set theXMPline to "<?xpacket end=\"w\"?>"
do shell script "echo " & quoted form of theXMPline & " >> " & quoted form of theDistPathXmpFile

-------------出来上がったXMPファイルにラベルを塗って保存したフォルダを開く
tell application "Finder"
set label index of alias (((theSaveXmpPath & theXmpFileName))) to 5
open folder theSaveXmpPath
activate
end tell
end if
else if button returned of the result is "終了" then
end if





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

to replace(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 replace

on decodeURL(str)
set scpt to "php -r 'echo urldecode(\"" & str & "\");'"
return do shell script scpt
end decodeURL

「GoogleMap2Bridgev1.rtf」をダウンロード


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

|

« [AppleScript]quicklookを再起動する | トップページ | [AppleScript]Flash Player をアンインストール »

AdobeBridge」カテゴリの記事