Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/usr/bin/env osascript -l JavaScript
function pathjoin() {
var arr = Array.prototype.slice.call(arguments);
var dest = $.NSString.pathWithComponents(ObjC.wrap(arr));
return ObjC.unwrap(dest);
}
var HOMEDIR = ObjC.unwrap($.NSHomeDirectory());
function run(input, parameters) {
if (input.length < 2) {
console.log("PhotosDropbox <Source Album> <Dropbox Path>");
return [];
}
var Photos = Application("Photos");
console.log("Getting album:", input[0])
var album = Photos.albums[input[0]];
console.log("Have album:", album.id());
var DEST = pathjoin(HOMEDIR, 'Dropbox', input[1]);
console.log(DEST)
var fm = $.NSFileManager.defaultManager;
var itemsToSync = album.mediaItems().filter(function (item) {
if (!item.favorite())
return false;
var fpath = pathjoin(DEST, item.filename());
var exists = ObjC.unwrap(fm.fileExistsAtPath(fpath));
return !exists;
});
console.log("Syncing", itemsToSync.length, "Items");
Photos.export(itemsToSync, {
to: Path(DEST)
});
console.log("Exported");
return [];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.