Quantcast
Channel: Planet DTP@jp
Viewing all articles
Browse latest Browse all 4835

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

$
0
0

(*
GoogleMap2Bridgev2.scpt
v1からURLデコード部分とawk文を修正した
GoogleMapURLから東経北緯を取得して
XMPファイルを作成します
Adobe Bridge GPSタブで写真に撮影場所として追加する事が出来ます
詳しくは
http://force4u.cocolog-nifty.com/skywalker/2013/02/applescriptsg-1.html
ご覧下さい
*)



--------------デフォルトアンサー用に東京タワーのURL
settheOrgGoogleMapUrlto"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" astext

--------------URLをペーストするダイアログを出す
display dialog"GoogleMapURLをペーストしてください" default answerthetheOrgGoogleMapUrlwith icon 1 with title"GoogleMapURLをペーストしてください" default button 1
--------------リザルトをリスト形式で格納
copytheresultaslistto {thetheOrgGoogleMapUrl, BottPressNo}
--------------東経と北緯のLLの値を取り出す
settheAwkComLLto"echo " & quoted formoftheOrgGoogleMapUrl& "| awk -F \"ll=\" '{print($2)}' |awk -F \"&\" '{print($1)}' " astext
settheAwkComQto"echo " & quoted formoftheOrgGoogleMapUrl& "| awk -F \"q=\" '{print($2)}' |awk -F \"&\" '{print($1)}' " astext

--------------エラー制御
try
settheGoogleLlNotodo shell scripttheAwkComLLastext
iftheGoogleLlNois"" then
display alert"GPSデータを取得出来ませんでした"
endif
onerror
settheGoogleLlNotodo shell scripttheAwkComQastext
iftheGoogleLlNois"" then
display alert"GPSデータを取得出来ませんでした"
endif
endtry
--------------llの値をリスト形式に整形
setAppleScript's text item delimitersto {","}
settheGoogleLlNoListtoeverytext itemoftheGoogleLlNoaslist
--------------Latitude60進数の処理
settheLatitudetoitem 1 oftheGoogleLlNoListastext
settheIntegerLatitudetotheLatitudediv 1 astext
settheLatitudeto (text 2 thru 8 of (((theLatitudemod 1) asstring) & "000000") asstring)
settheLatitudetotheIntegerLatitude& theLatitude
settheDecimalLatitudeAto (((theLatitudeasnumber) - (theIntegerLatitudeasnumber)) asnumber) * 60
settheIntegerDecimalLatitudeAtotheDecimalLatitudeAdiv 1 astext
settheDecimalLatitudeBto (((theDecimalLatitudeAasnumber) - (theIntegerDecimalLatitudeAasnumber)) asnumber) * 100 asinteger
settheLatitudetotheIntegerLatitude& "," & theIntegerDecimalLatitudeA& "." & theDecimalLatitudeB& "N" astext
--------------Longitude60進数の処理
settheLongitudetoitem 2 oftheGoogleLlNoListastext
settheIntegerLongitudetotheLongitudediv 1 astext
settheLongitudeto (text 2 thru 8 of (((theLongitudemod 1) asstring) & "000000") asstring)
settheLongitudetotheIntegerLongitude& theLongitude
settheDecimalLongitudeAto (((theLongitudeasnumber) - (theIntegerLongitudeasnumber)) asnumber) * 60
settheIntegerDecimalLongitudeAtotheDecimalLongitudeAdiv 1 astext
settheDecimalLongitudeBto (((theDecimalLongitudeAasnumber) - (theIntegerDecimalLongitudeAasnumber)) asnumber) * 100 asinteger
settheLongitudetotheIntegerLongitude& "," & theIntegerDecimalLongitudeA& "." & theDecimalLongitudeB& "E" astext
--------------ダイアログ用に改行を入れて整形しておく
settneAnstotheLatitude& "\n" & theLongitude
--------------出来上がりデータをダイアログで表示
display dialog"Bridge用のGPSの値です" default answerthetneAnswith icon 1 with title"Adobe Bridge GPS" default button 1 buttons {"XMPファイルも作る", " 終了"}
--------------XMPファイルも作る場合の始まり
ifbutton returnedoftheresultis"XMPファイルも作る" then
--------------XMPファイルとBridgeの関連づけの確認
do shell script"date > /tmp/ApplicationChk.xmp"
settheTmpXmpFileto (thepath tostartup diskasstring) & "tmp:ApplicationChk.xmp" asalias
settheFileInfotodefault applicationof (info fortheTmpXmpFile) astext
--------------Bridgeが未インストールの可能性のエラー制御
if (theFileInfocontains"Bridge") isfalsethen
display alert"XMPファイルがAdobe Bridgeに関連づけられていません"
--------------XMPファイル作成の本処理のはじまり
elseif (theFileInfocontains"Bridge") istruethen
--------------XMPファイルの保存先ディレクトリを取得
settheSaveXmpPathto (thepath toapplication supportfromuser domainastext) & "Adobe:XMP:Metadata Templates:"
--------------東経と北緯データの再取得(ここは別な方法があったかな)
settheGoogleLlNoQtodo shell scripttheAwkComQastext
--------------qの値=検索語句の有無
iftheGoogleLlNoQis"" then
--------------qの値=検索語句が無い場合はファイル名を日付にするため日付の処理
settheDateTimeto (do shell script"date +'%Y%m%d_%H%M%S'" asstring)
settheXmpFileNameto (theLatitude& "_" & theLongitude& "_" & theDateTime& ".xmp") astext
settheXmpFileNametomyreplace(theXmpFileName, ",", ".") astext
settheGooogleMapQtotheLatitude& " " & theLongitude
else
--------------検索語句がある場合はデコードしてファイル名にする
settheGooogleMapQtomydoDecodeURL(theGoogleLlNoQ)
settheXmpFileNameto (theGooogleMapQ& ".xmp") astext
endif
--------------XMPファイルの保存先を作成
settheDistPathXmpFileto (POSIX pathof ((theSaveXmpPath& theXmpFileName) astext)) astext
--------------ファイルを作っておく(既に同名がある場合は上書きになる)
do shell script"touch " & quoted formoftheDistPathXmpFile
--------------パスを格納
settheDistFileXmpFileto (POSIX filetheDistPathXmpFile) asalias
-----------------------------------------------ここからXMPファイルの作成
-------------XMPファイルの最初の1行
settheXMPlineto"<?xpacket begin=\"\" id=\"W5M0MpCehiHzreSzNTczkc9d\"?>"
do shell script"echo " & quoted formoftheXMPline& " > " & quoted formoftheDistPathXmpFile
-------------XMPファイル
settheXMPlineto"<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 formoftheXMPline& " >> " & quoted formoftheDistPathXmpFile
-------------宣言
settheXMPlineto"<rdf:RDF xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\">"
do shell script"echo " & quoted formoftheXMPline& " >> " & quoted formoftheDistPathXmpFile
settheXMPlineto"<rdf:Description rdf:about=\"\""
do shell script"echo " & quoted formoftheXMPline& " >> " & quoted formoftheDistPathXmpFile
settheXMPlineto" xmlns:dc=\"http://purl.org/dc/elements/1.1/\""
do shell script"echo " & quoted formoftheXMPline& " >> " & quoted formoftheDistPathXmpFile
settheXMPlineto" xmlns:photoshop=\"http://ns.adobe.com/photoshop/1.0/\""
do shell script"echo " & quoted formoftheXMPline& " >> " & quoted formoftheDistPathXmpFile
settheXMPlineto" xmlns:Iptc4xmpCore=\"http://iptc.org/std/Iptc4xmpCore/1.0/xmlns/\""
do shell script"echo " & quoted formoftheXMPline& " >> " & quoted formoftheDistPathXmpFile
settheXMPlineto" xmlns:Iptc4xmpExt=\"http://iptc.org/std/Iptc4xmpExt/2008-02-29/\""
do shell script"echo " & quoted formoftheXMPline& " >> " & quoted formoftheDistPathXmpFile
settheXMPlineto" xmlns:exif=\"http://ns.adobe.com/exif/1.0/\""
do shell script"echo " & quoted formoftheXMPline& " >> " & quoted formoftheDistPathXmpFile
-------------photoshop
settheXMPlineto" photoshop:Instructions=\"" & theGooogleMapQ& "\""
do shell script"echo " & quoted formoftheXMPline& " >> " & quoted formoftheDistPathXmpFile
-------------Iptc4xmpCore
settheXMPlineto" Iptc4xmpCore:Location=\"" & theGooogleMapQ& "\""
do shell script"echo " & quoted formoftheXMPline& " >> " & quoted formoftheDistPathXmpFile
-------------exif:
settheXMPlineto" exif:GPSLatitude=\"" & theLatitude& "\""
do shell script"echo " & quoted formoftheXMPline& " >> " & quoted formoftheDistPathXmpFile
settheXMPlineto" exif:GPSProcessingMethod=\"MANUAL\""
do shell script"echo " & quoted formoftheXMPline& " >> " & quoted formoftheDistPathXmpFile
settheXMPlineto" exif:GPSAltitude=\"0.00 m\""
do shell script"echo " & quoted formoftheXMPline& " >> " & quoted formoftheDistPathXmpFile
settheXMPlineto" exif:GPSLongitude=\"" & theLongitude& "\">"
do shell script"echo " & quoted formoftheXMPline& " >> " & quoted formoftheDistPathXmpFile
-------------dc
settheXMPlineto" <dc:subject>"
do shell script"echo " & quoted formoftheXMPline& " >> " & quoted formoftheDistPathXmpFile
settheXMPlineto" <rdf:Bag>"
do shell script"echo " & quoted formoftheXMPline& " >> " & quoted formoftheDistPathXmpFile
settheXMPlineto" <rdf:li>" & theGooogleMapQ& "</rdf:li>"
do shell script"echo " & quoted formoftheXMPline& " >> " & quoted formoftheDistPathXmpFile
settheXMPlineto" </rdf:Bag>"
do shell script"echo " & quoted formoftheXMPline& " >> " & quoted formoftheDistPathXmpFile
settheXMPlineto" </dc:subject>"
do shell script"echo " & quoted formoftheXMPline& " >> " & quoted formoftheDistPathXmpFile
-------------Iptc4xmpExt
settheXMPlineto" <Iptc4xmpExt:LocationShown>"
do shell script"echo " & quoted formoftheXMPline& " >> " & quoted formoftheDistPathXmpFile
settheXMPlineto" <rdf:Bag>"
do shell script"echo " & quoted formoftheXMPline& " >> " & quoted formoftheDistPathXmpFile
settheXMPlineto" <rdf:li"
do shell script"echo " & quoted formoftheXMPline& " >> " & quoted formoftheDistPathXmpFile
settheXMPlineto" Iptc4xmpExt:Sublocation=\"" & theGooogleMapQ& "\"/>"
do shell script"echo " & quoted formoftheXMPline& " >> " & quoted formoftheDistPathXmpFile
settheXMPlineto" </rdf:Bag>"
do shell script"echo " & quoted formoftheXMPline& " >> " & quoted formoftheDistPathXmpFile
settheXMPlineto" </Iptc4xmpExt:LocationShown>"
do shell script"echo " & quoted formoftheXMPline& " >> " & quoted formoftheDistPathXmpFile
-------------XMPの終了
settheXMPlineto" </rdf:Description>"
do shell script"echo " & quoted formoftheXMPline& " >> " & quoted formoftheDistPathXmpFile
settheXMPlineto" </rdf:RDF>"
do shell script"echo " & quoted formoftheXMPline& " >> " & quoted formoftheDistPathXmpFile
settheXMPlineto"</x:xmpmeta>"
do shell script"echo " & quoted formoftheXMPline& " >> " & quoted formoftheDistPathXmpFile
settheXMPlineto"<?xpacket end=\"w\"?>"
do shell script"echo " & quoted formoftheXMPline& " >> " & quoted formoftheDistPathXmpFile

-------------出来上がったXMPファイルにラベルを塗って保存したフォルダを開く
tellapplication"Finder"
setlabel indexofalias (((theSaveXmpPath& theXmpFileName))) to 5
openfoldertheSaveXmpPath
activate
endtell
endif
elseifbutton returnedoftheresultis"終了" then
endif





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

toreplace(theText, orgStr, newStr)
setoldDelimtoAppleScript's text item delimiters
setAppleScript's text item delimiterstoorgStr
settmpListtoeverytext itemoftheText
setAppleScript's text item delimiterstonewStr
settmpStrtotmpListastext
setAppleScript's text item delimiterstooldDelim
returntmpStr
endreplace

ondoDecodeURL(theUrlEncodeText)
settheScptto ("echo \"<?php print(urldecode('" & theUrlEncodeText& "'));?>\" | php")
returndo shell scripttheScpt
enddoDecodeURL


元記事はこちら

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

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


Viewing all articles
Browse latest Browse all 4835

Trending Articles