Created
November 29, 2015 23:38
-
-
Save tjfontaine/af36c5e3080b21d19696 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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