May 2025 Archives

My wife and I travel a bit and on most occasions, we'll take both our iPhones and a big Nikon D750 with equally weighty lens for zooming in a bit or catching something really quick and quickly. (I'm fumblefingers with the iPhone when trying to do anything fast, and the Nikon is point-and-shoot easy with a big red button.)

The problem with this arrangement is that the Nikon pics don't end up with location information on them, and I'm not about to spend bucks for an awkward GPS location dingus that attaches to the camera's hotshoe. That's just asking for more trouble. However, when we're both taking pictures, location information is "just over there" in the iPhone, and as long as the dates and times agree, more or less, it seemed reasonable to just take the location info from the iPhone photo and "smear" it onto the subsequent Nikon photos.

Now, this algorithm is simple and robust, but it has its limitations. Clearly, it won't work if I took a Nikon shot before she took an iPhone shot. That Nikon shot would be lumped in with previous phone photos. And it doesn't help if the Nikon was the only camera used at a location, or if the Nikon is in motion without accompanying iPhone photos. I had a brief go at correcting these problems programatically, but it really didn't seem to be worth it for the odd photo which was mis-located.

Practically, the solution is reasonably simple: just take an iPhone photo phirst, then take Nikon photos to my heart's content.

Here's the AppleScript, provided without any warranty whatsoever. And if you make any improvements to it, please feel free to publish them—just let me know, please, so I can take advantage of your smarts!

Also, thanks to Moth Software for their very useful AppleScript to HTML converter so you can see pretty code below!

tell application "Photos"
    
    set
theKeyword to "Automatic Location"
    set
lastLocation to {missing value, missing value}
    
    set
currentSelection to the selection
    
    repeat with
thisPhoto in currentSelection
        
        if
location of thisPhoto is not {missing value, missing value} then
            set
lastLocation to location of thisPhoto
        else if
location of thisPhoto is {missing value, missing value} ¬
            and
lastLocation is not {missing value, missing value} then
            set
location of thisPhoto to lastLocation
            if
keywords of thisPhoto is missing value then
                set
keywords of thisPhoto to theKeyword
            else
                set
keywords of thisPhoto to (get keywords of thisPhoto) & theKeyword
            end if
        end if
        
        
print location
        
print keywords of thisPhoto
    end repeat
    
end tell