メインコンテンツへスキップ

⚠️ Please note that this topic or post has been archived. The information contained here may no longer be accurate or up-to-date. ⚠️

Applescript to copy Google Maps address to keywords

コメント

8件のコメント

  • Francis Mariani
    This is the AppleScript for Aperture. I recently had to add a Google Maps API key to make this work, so I found the appropriate Google Maps API link to generate the key - you need to provide credit card info, but since I'll be doing this less than 25,000 times a day, it won't cost anything.

    tell application "Aperture"
    set imageSel to selection
    repeat with i from 1 to count of imageSel
    tell library 1
    tell item i of imageSel
    set lat to get latitude
    set long to get longitude

    if (long is missing value) or (lat is missing value) then
    display dialog "Please select a geotagged image" with title "GPS data missing" buttons {"Okay"}
    else
    set lat to my set_decimal_delimiter_to_dot(lat as string)
    set long to my set_decimal_delimiter_to_dot(long as string)

    tell application "JSON Helper"
    --set reverse_geocode_request to fetch JSON from ("https://maps.googleapis.com/maps/api/geocode/json?latlng=" & lat & "," & long & "&sensor=false")
    set reverse_geocode_request to fetch JSON from ("https://maps.googleapis.com/maps/api/geocode/json?latlng=" & lat & "," & long & "&key=my_google_maps_api_key")
    set address_components to get address_components of item 1 of results of reverse_geocode_request

    -- making a list (Array) of address component names
    set address_components_list to {}
    repeat with j from 1 to count of address_components
    if item 1 of |types| of item j of address_components is in {"route", "sublocality", "locality", "administrative_area_level_1", "country"} then
    copy long_name of item j of address_components to beginning of address_components_list --adding them at the beginning, sorts locations from general to specific
    end if
    end repeat
    end tell

    -- making and assigning a keyword for each item in the address components list
    -- each keyword will have the previous item(s) as a parent keyword
    -- this will create a nested list of location keywords
    repeat with k from 1 to count of address_components_list
    -- making a list (Array) of parent keywords from the previous item(s) in the address components list
    set parents_list to {}
    repeat with l from 1 to (k - 1)
    copy item (k - l) of address_components_list to end of parents_list
    end repeat

    -- setting delimiter to "\t": so when parents_list get converted to String, a tab is inserted as the separator
    -- (the nested keywords for the 'parents' param expects a tab-separated list of parent keywords)
    set AppleScript's text item delimiters to " "

    make new keyword with properties {name:item k of address_components_list, parents:parents_list as string}
    end repeat
    end if

    end tell
    end tell
    end repeat
    end tell

    on set_decimal_delimiter_to_dot(this_text)
    set AppleScript's text item delimiters to ","
    set the text_items to every text item of this_text
    set AppleScript's text item delimiters to "."
    set this_text to the text_items as string
    set AppleScript's text item delimiters to ""
    return this_text
    end set_decimal_delimiter_to_dot
    0
  • RobiWan
    [quote="Francesco Mariani" wrote:

    I am looking for an AppleScript to copy Google Maps address components to Capture One keywords, e.g. Street Name, City, Country.


    I'm looking for something like that too.
    0
  • Sean Murphy
    Hi Francis,
    Which portions of your previous script are you needing Capture One to do? I would assume you're shooting or importing images into Capture One and want to grab the lat/long data, then go out to Google Maps API to gather the address components and then save it back to the image in Capture One?
    Sean
    0
  • Eric Valk
    Hi All
    Here is Fancis's Applescript with the Aperture interface replaced by a Capture One interface.

    I've copied the Google API code, but don't have the time o debug or check it. but if it was working before, it should be working now.


    tell application "Capture One 11"
    set imageSel to selected variants
    repeat with i from 1 to count of imageSel
    tell item i of imageSel
    set lat to get EXIF latitude of its parent image
    set long to get EXIF longitude of its parent image

    if (long is missing value) or (lat is missing value) then
    display dialog "Please select a geotagged image" with title "GPS data missing" buttons {"Okay"}
    else
    set lat to my set_decimal_delimiter_to_dot(lat as string)
    set long to my set_decimal_delimiter_to_dot(long as string)

    tell application "JSON Helper"
    --set reverse_geocode_request to fetch JSON from ("https://maps.googleapis.com/maps/api/geocode/json?latlng=" & lat & "," & long & "&sensor=false")
    set reverse_geocode_request to fetch JSON from ("https://maps.googleapis.com/maps/api/geocode/json?latlng=" & lat & "," & long & "&key=my_google_maps_api_key")
    set address_components to get address_components of item 1 of results of reverse_geocode_request

    -- making a list (Array) of address component names
    set address_components_list to {}
    repeat with j from 1 to count of address_components
    if item 1 of |types| of item j of address_components is in {"route", "sublocality", "locality", "administrative_area_level_1", "country"} then
    copy long_name of item j of address_components to beginning of address_components_list --adding them at the beginning, sorts locations from general to specific
    end if
    end repeat
    end tell

    -- making and assigning a keyword for each item in the address components list
    -- each keyword will have the previous item(s) as a parent keyword
    -- this will create a nested list of location keywords
    repeat with k from 1 to count of address_components_list
    -- making a list (Array) of parent keywords from the previous item(s) in the address components list
    set parents_list to {}
    repeat with l from 1 to (k - 1)
    copy item (k - l) of address_components_list to end of parents_list
    end repeat

    -- setting delimiter to "\t": so when parents_list get converted to String, a tab is inserted as the separator
    -- (the nested keywords for the 'parents' param expects a tab-separated list of parent keywords)
    set AppleScript's text item delimiters to " "

    make new keyword with properties {name:item k of address_components_list, parents:parents_list as string}
    end repeat
    end if

    end tell
    end repeat
    end tell

    on set_decimal_delimiter_to_dot(this_text)
    set AppleScript's text item delimiters to ","
    set the text_items to every text item of this_text
    set AppleScript's text item delimiters to "."
    set this_text to the text_items as string
    set AppleScript's text item delimiters to ""
    return this_text
    end set_decimal_delimiter_to_dot
    0
  • Francis Mariani
    Eric, sorry for the very tardy reply. Thanks very much for offering the updated script. Happy New Year!
    0
  • Eric Valk
    [quote="Francesco Mariani" wrote:
    Eric, sorry for the very tardy reply. Thanks very much for offering the updated script. Happy New Year!

    No problem. Life sometimes changes your plans.

    But - does it work now? - if it needed fixes, what did you change?
    0
  • Rick Allen

    You might want to look at LOCATION helper by the same developer of JSON helper 

    Location Helper (mousedown.net)

     

    0
  • Francis Mariani

    Thanks for the updates and keeping this alive.

    0

投稿コメントは受け付けていません。