Unofficial archive. This is a read-only, community-run archive of the Apple Support Community. It is not affiliated with or endorsed by Apple Inc.

How to export folder of multiple albums from Photos

I have Photos Version 2.0 (3130.0.240) on a desktop Mac with O.S Sierra 10.12.3.


I have arranged and organized many photos in the Mac Photos program into multiple Folders which are then broken down into subcategories or sub-folders with a couple of albums in each. See reference below -



Albums >

Vacation Photos (Folder) >

Bali Trip (Folder) > Albums > Photos (150 photos)

Sydney Trip (Folder) > Album > Photos (76 photos)

Brisbane Trip (Folder) > Albums > Photos (126 photos)

Vancouver Trip (Folder) > Albums > Whistler Photos (48 photos)

> Van City Photos (96 photos)


How do I then export the core folder of 'Vacation Photos (Folder) >' to an external hard-drive and so someone else can have a copy of them in the high quality so they can import into their own photo album and maintain all of the sub-folders/categories?


28 replies

That would require a bit of programming. Right now this line takes the complete list of all photos in an album (get media itemsofalbumtName) and writes them as the originals into to folder tfolder.

There is no command in the AppleScript dictionary for Photos to use the title as filename.

You would have to progr 00002237 am a loop to construct a new filename from the title, and use this new filename in the "to file" part of the export statement.


See the dictionary for scripting Photos:





export v : Export media items to the specified location as files

export list of media item : The list of media items to export.to file : The destination of the export.[using originals boolean] : Export the original files if true, otherwise export rendered jpgs. defaults to false.

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 the 00004000 CurrentItem 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

Hi léonie, many thanks dor your improved script.


On my MacBook it works perfectly if I choose original photos. If I choose modified ones and want to export several albums, the script stops exporting after 1-3 albums.


Do you have any idea how to clear that issue?

Which version of macOS are you running? The timeout errors are typical for Photos on Yosemite and El Capitan. On Sierra are the scripts more robust.


Can you identify the photo, where the script is stopping the export? Check, if the photo can be edited or if you can export it manually.

Nothing - the original dates are included in the photo EXIF/IPTC data and will be shown when you use any photo software to view the photos metadata


The file metadata which you are looking at has nothing to do with the Photo metadata nor can Léonie's script modify the file meta data - there is third party software you can acquire that can set file metadata to match the Photo metadata


LN

Hi Leonie,
Thanks for all your work. I tried Jacques Rioux's script, which worked fine. But, as you probably know, the time & datesettings changed to the actual date. Is there a way to keep the original photo information?
Kind regards, Eric.

But, as you probably know, the time & datesettings changed to the actual date. Is there a way to keep the original photo information?

Not directly in Photos. Photos will usually keep the original file creation dates when exporting the original image files. But but if you export the edited versions, Photos needs to render a new image file, and this file will have the creation date of the export. But the the original capture date will be embedded as EXIF tag.


If you have Graphic Converter 10, you can use it to change the file creation date to the EXIF capture date.

Hi Leonie


thanks for all the helpful hints / scripts so far. I'm using your script to export edited versions to the HDD and do further actions (sorting, renaming, archiving on NAS) using Hazel. The only remaining issue I have are videos. There are no EXIF information available after export showing original capture date. So what I'm trying to do is saving the original date into the Title (which I can do already) and export the video file with current name & Title as new name of the file.


This is what I don't get to work. I don't see any reference to the filename at all, so I have no clue how to concatenate name and title. Can you please help?


This seems to be the relevant part of the script saving file to the drive:

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 album tName) to (tFolder as alias) with using originals -- export the original versions
else
export (get media items of album tName) to (tFolder as alias) without using originals -- export the edited versions
end if
end repeat
end if
end tell
​

Thanks,
Thomas

Thanks for your quick answer.


I've seen those scripts beforehand, cause I tried to get this solved by myself already.


My issue is, that I'm not able to adopt the mechanism of those scripts into my export script. I do not see where the file name of the exported file is specified and do not know how to bring filename and Title together during the export.

My issue is, that I'm not able to adopt the mechanism of those scripts into my export script. I do not see where the file name of the exported file is specified and do not know how to bring filename and Title together during the export.

The Apple Script dictionary for Photos does not allow to specify a new filename on export or even to specify, that the current title should be used as the filename.

This is all that can be specified for the export using a script:

export v : Export media items to the specified location as 00004000 files


export list of media item : The list of media items to export.

to file : The destination of the export.

[using originals boolean] : Export the original files if true, otherwise export rendered jpgs. defaults to false.

For your videos you could modify the provided scripts to change the title of the video to the date plus the filename.

For example - for a list of selected videos you can change the title to the capture date plus the filename like this:


tell application "Photos"


activate

set imageSel to (get selection) -- get selected images r videos

if imageSel is {} then

error "Please select some images."

else

repeat with next_image in imageSel


-- retrive the date

set capture_date to (the date of next_image)

set short_capture_date_string to the short date string of capture_date


-- set capture_time_string to the time string of capture_date

set fname to the filename of next_image

set new_title to short_capture_date_string & "-" & fname


tell next_image

set the name to new_title as text

end tell

end repeat


-- return new_title

end if

end tell



Then export your videos manually from Photos with "File > Export, and file naming: Use title.

That's what I thought - thanks for clarifying. I guess I have to live with the wrong creation date for the time being. I use many albums for many videos and it's not the way fwd exporting them manually.


As good as most things work on a Mac: Some things remain strange to stupid (e.g. I don't understand why pictures keep the creation date and movies don't. Both are converted during export so I don't see a reason for different behavior.) But that's an Apple thing.


Again, thanks for your quick and great support.


Cheers

Thomas

(e.g. I don't understand why pictures keep the creation date and movies don't. Both are converted during export so I don't see a reason for different behavior.)

It is a problem of the EXIF standard. Photos do have an EXIF tag with a creation date, videos don't.

Hi Léonie

How could I change this line "export (get media itemsofalbumtName) to (tFolderasalias) with using originals" in your script to use the titles of the photos as filenames (instead of the original filenames)?

Here's how:


1 - download and install the user contributed AppleScript Export Albums to Folders - Jacques Rioux's Script.

You can download a compiled version of the script as an application from this tutorial site: P01 - Applescripts from Photos’ User Tips Compiled as Applications

2 - with your library open launch the script.


3 - in the resulting window select the Control-click on the albums you want exported.

User uploaded file

3 - Each will be exported to a folder with the same name as the album. Those folders will be situated in a folder titled PHOTOS-Album:

User uploaded file

User uploaded file

it is not - and of course there is no reason it "should be" - in fact very few people have requested it here and I doubt that it would be used much at all - you certainly can suggest to Apple - http://www.apple.com/feedback/


LN

Hi Léonie


What do I need to change by your script, that the copy get's the origin create date of a photo and not the date of the export? Do you have any ideas?


Regards,

Marcel.

Thank you Larry,


I found it out just a few seconds before you answered 😉. Thank you anyway for your reply. Now I will export my complete library as backup 😎.


Regards.

@Old Toad you're a rockstar!! thank you, that did kind of work....


However, I did have to 00004000 individually go through each album and it didn't show the 'Folders' within the menu to export. Which will mean have to re-order thousands of photos back into each folders/sub-folders. Are there any other work arounds?


Shouldn't this be a standard export feature of Apple Photos? i.e File > Export > Export Folder?

@larryHN I appreciate the link, I will make the suggestion to Apple. There is no reason why it shouldn't be a standard feature to keep photos organized and considering someone has gone to the effort of creating an Apple Script shows that people do use batch exporting from photos.

Ok - you are correct - but it does not currently exist and I deal with what is not what people can dream up - Apple deals with that and we use what they come up with or choose not to use it and use what someone else comes up with - so far I've chosen wha Apple comes up with and I understand that I can not change that - I can only use it or not use it - life is simple


LN

léonie, thanks for publishing your script; very useful!


Do you have any thoughts on the original question: how it might be possible to do this but to include folders (as defined in Photos) as part of the exported structure? I've got albums in folders and it would be nice to be able to export the entire hierarchy. If it was a one-time thing, I wouldn't worry and would just do the export with your current script, then move the exported folders manually. However, I'd like to use a script to regularly export new folders and albums, as a type of backup. I do back up the Photos library using several methods but I'd also like to have a copy of my Photos hierarchy as exported folders.


Thanks.

The Apple Script dictionary of Photos allows to find the name of the containing folder for an album or the a subfolder. But it would be a lot of work to write the Apple Script program to create the sub folder hierarchy and to test if the folders already exist or need to be created and then to export the photos for each album to the correct folder.


I have currently no need for such a script, because I stopped using the nested folders with albums when I started to use iCloud Photo Library. My folders and albums keep vanishing when syncing with iCloud. Now I am mainly using the moments and collections. They are structuring the my library exactly as I need them. And when I export my original photos with the subfolder format "Moment Name", the folder names will show the capture date and the location. That suffices for me, when I need to recover originals photos to find them quickly.

Hello Léonie


This is a very very helpful script léonie! It helped me already a lot to export my Photos Albums to a Windows System for Backup purposes. On Windows I use Batch rename utility to rename the Photos to the Folder name they are stored in and adding a sequential number -001, 002 , etc.

All this was an export option in iPhoto. No idea why apple has deleted this in the new Photos program.


What do you think: would it be a lot a work to add the "rename to folder name with sequential numbering" option to your script?


Regards

Martin

What do you think: would it be a lot a work to add the "rename to folder name with sequential numbering" option to your script?

It would be difficult, because a photo can be in many albums, and thus in alums in many different folders.

I keep getting this error:


error "Photos got an error: AppleEvent timed out." number -1712


Any idea of what to do? Is this because my entire library is not downloaded to my computer and some of it is on iCloud?

Any idea of what to do? Is this because my entire library is not downloaded to my computer and some of it is on iCloud?

Yes, if your network is slow, it might give these timeout errors.

You may also see them, if you do not reply fast enough, when the script prompts you select items or other input. I would hide all other windows when running the script, so you can see the dialog panels.

Ok, you're right! Thanks again for sharing your current script. It helps me a lot 🙂