Here is a version with a sorted album list:
-- modified by Leonie
-- to include a sorted list of albums to pick from
-- a dialog for the location of the default folder
-- a dialog to chose between exporting the originals or the modified versions
-- a prompt with the list of the exported album names
on sortList(theList)
-- from: https://developer.apple.com/library/content/documentation/LanguagesUtilities/Con ceptual/MacAutomationScriptingGuide/ManipulateListsofItems.html
set theIndexList to {}
set theSortedList to {}
try
repeat (length of theList) times
set theLowItem to ""
repeat with a from 1 to (length of theList)
if a is not in theIndexList then
set theCurrentItem to item a of theList as text
if theLowItem is "" then
set theLowItem to theCurrentItem
set theLowItemIndex to a
else if theCurrentItem comes before theLowItem then
set theLowItem to theCurrentItem
set theLowItemIndex to a
end if
end if
end repeat
set end of theSortedList to theLowItem
set end of theIndexList to theLowItemIndex
end repeat
on error errMsgnumbererrorNumber
return {"An unknown error occurred:"} & theSortedList
end try
return theSortedList
end sortList
-- select the destination folder -- Leonie
set destination to choose folder with prompt "Select a destination folder to save the albums to" default location (the path to the pictures folder as alias)
set dest to ((the POSIX path of destination) as text) as POSIX file as text
-- set dest to "/Users/Jobs/Pictures/Albums/" as POSIX file as text -- the destination folder (use a valid path). -- change this to your default path for a fixed folder
-- Display a dialog to select the original images or the edited versions
set r to display dialog "Do you want to export the originals or the edited versions?" buttons {"Originals", "Edited versions"} default button 1 with icon 2
set orig to (button returned of r is "Originals")
tell application "Photos"
activate
set unsorted to (name of albums)
end tell
set l to sortList(unsorted) -- Leonie
set albNames to choose from listlwith prompt "Select some albums" with multiple selections allowed
tell application "Photos"
if albNames is not false then -- not cancelled
repeat with tName in albNames
set tFolder to dest & tName
my makeFolder(tFolder) -- create a folder named (the name of this album) in dest
if orig then
export (get media items of albumtName) to (tFolder as alias) with using originals-- export the original versions
else
export (get media items of albumtName) to (tFolder as alias) without using originals-- export the edited versions
end if
end repeat
end if
end tell
tell application "Finder"
open (tFolder as alias)
return {"Done: "} & albNames
end tell
on makeFolder(tPath)
do shell script "mkdir -p " & quoted form of POSIX path of tPath
end makeFolder