Skip to content

Instantly share code, notes, and snippets.

@quentinms
Last active September 19, 2020 19:18
Show Gist options
  • Save quentinms/61ce7bdee9148f5b4ce88e5029d7ecb7 to your computer and use it in GitHub Desktop.
Save quentinms/61ce7bdee9148f5b4ce88e5029d7ecb7 to your computer and use it in GitHub Desktop.
Tag GoPro videos with GPS metadata in Photos.app (macOS)
// GoPro Hero 5/6 videos have GPS metadata but Photos doesn't recognize them for whatever reason.
// This script loads selected items from Photos, analyzes them with exiftool, and adds back the GPS metadata in a way Photos can understand.
// Run this in Script Editor, Automator or save it as a service. Change the export folder.
// Requires exiftool (https://www.sno.phy.queensu.ca/~phil/exiftool/)
function run() {
const Photos = new Application("Photos")
Photos.includeStandardAdditions = true
const app = Application.currentApplication()
app.includeStandardAdditions = true;
const selected = Photos.selection()
Photos.export(selected, {to: '/Users/quentin/Downloads/', usingOriginals: true})
for (const item of selected){
addGPSToMedia(item)
}
console.log(`Processed ${selected.length} videos`)
}
function addGPSToMedia(item) {
const filename = item.filename()
console.log(`Looking at ${filename}`)
if (item.location()) {
console.log(`${filename} already has GPS info: ${item.location()}`)
return
}
const lat = app.doShellScript(`export PATH=$PATH:/usr/local/bin/; exiftool -s -s -s -n -GPSLatitude /Users/quentin/Downloads/${filename}`)
const lon = app.doShellScript(`export PATH=$PATH:/usr/local/bin/; exiftool -s -s -s -n -GPSLongitude /Users/quentin/Downloads/${filename}`)
if (!lat || !lon) {
console.log(`No GPS info for: ${filename}`)
return
}
item.location = [lat,lon]
console.log(`${filename} is at ${item.location()}`)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment