Skip to content

Instantly share code, notes, and snippets.

@companje
Last active December 29, 2019 21:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save companje/889e0acae02304d944813cff5569b97b to your computer and use it in GitHub Desktop.
Save companje/889e0acae02304d944813cff5569b97b to your computer and use it in GitHub Desktop.
AppleScript JXA - Apple Photos script for organising photos into albums.
//Create a new ‘Quick Action’ in ‘Automator’, then 'Add JavaScript' and assign a keyboard shortcut to it for ideal workflow.
//by Rick Companje, May 2019
var Photos = Application("Photos")
Photos.includeStandardAdditions = true
var sel = Photos.selection();
var folder = Photos.folders.byName("Overig");
if (sel.length>0) {
//show list with all album names ordered
var names = folder.albums.name(); //original order for index
var namesWithIndex = names.map(function(el,index) { return el }); // + " #" + index; });
var namesSorted = namesWithIndex.sort();
var result = Photos.chooseFromList(namesSorted, { withPrompt: sel.length + " foto's toevoegen aan een bestaand album?" })[0];
if (result) {
var selectedAlbum = Photos.folders.byName("Overig").albums.byName(result); //improved
Photos.add(sel, {to: selectedAlbum });
} else {
var result = Photos.displayDialog("Nieuw album maken?", { defaultAnswer: "", withIcon: 1 })
if (result) {
var album = Photos.make({new: "album", named: result.textReturned, at: folder });
Photos.add(sel, {to: album });
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment