Skip to content

Instantly share code, notes, and snippets.

@dtinth
Created October 29, 2014 15:18
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save dtinth/549230a2116fcd53bb33 to your computer and use it in GitHub Desktop.
Save dtinth/549230a2116fcd53bb33 to your computer and use it in GitHub Desktop.
iPhoto Location Export

iPhotoLocation

Exports the locations of photos in a photo album as JSON data...

osascript -l JavaScript iPhotoLocation.js "NAIST Internship"
[ {"id":4294967349,"latitude":34.435680000000005,"longitude":135.24453667,"altitude":15}
, {"id":4294967353,"latitude":34.43478,"longitude":135.243225,"altitude":14.8}
, {"id":4294967357,"latitude":34.43488,"longitude":135.243225,"altitude":14.6}
, {"id":4294967361,"latitude":34.435845,"longitude":135.24351332999998,"altitude":14.7}
, {"id":4294967369,"latitude":34.41083667,"longitude":135.29971332999997,"altitude":15.2}
...

So that you can put them in pretty maps:

Where I went

#!/usr/bin/env osascript -l JavaScript
ObjC.import('stdlib')
function run(argv) {
if (argv.length < 1) {
console.log('Please specify album name')
$.exit(1)
} else {
var photos = Application('iPhoto').albums[argv[0]].photos
var printer = new Printer()
;[].forEach.call(photos, function(photo) {
var info = {
id: photo.id(),
latitude: photo.latitude(),
longitude: photo.longitude(),
altitude: photo.altitude(),
}
if (info.latitude && info.longitude) {
printer.print(info)
}
})
printer.end()
}
}
function Printer() {
}
Printer.prototype.print = function(item) {
var prefix = this.printed ? ',' : '['
this.printed = true
console.log(prefix + ' ' + JSON.stringify(item))
}
Printer.prototype.end = function() {
console.log(this.printed ? ']' : '[]')
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment