Last active
December 29, 2019 21:37
-
-
Save companje/889e0acae02304d944813cff5569b97b to your computer and use it in GitHub Desktop.
AppleScript JXA - Apple Photos script for organising photos into albums.
This file contains 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
//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