export same albums from Photos

Hi


How can I export my library or part of my library from Photos with same album structure created?


For example, I have in Photos albums A, B, C, D, E etc


I want to export the pictures in a folders structure in OSX/finder as albums in Photos

So, in

-folder A with pictures in album A

- Folder B with pictures in album B


And so on


Thanks

Posted on May 11, 2015 7:18 AM

Reply
63 replies

Sep 23, 2016 4:37 PM in response to Old Toad

I've been using the script to export albums now for a bit and it works great.


We recently replaced our old iPhones with the new iPhone 7, and that's been causing a small problem. It seems the export is actually exporting a JPEG with the MOV still embedded in it, (guess based on the size). Is there a way to make sure the export doesn't include that? If I do a manual export I can get it to export the file fine, but I have no idea what parameters to change in the script to try to get this behavior (and I've been searching for a bit now).


Thanks in advance.

Oct 11, 2016 9:47 AM in response to Jacques Rioux

Hi I have tried the above "Script" in Sierra, it works perfectly, is it possible to only export one nominated folder which has many folders and albums within it as apposed to exporting the whole library? Also is it possible to rename the photos to run in a consecutive number range starting at "1" for each album as the photos are sorted in each album?


I have a large project with many folders and albums which I meticulously put into Photo's and have sorted all of the photos within each album, thinking I could then export in that structure out of photos.

Oct 12, 2016 8:50 AM in response to lloydfromchristchurch

Hi,


lloydfromchristchurch wrote:


is it possible to only export one nominated folder which has many folders and albums within it as apposed to exporting the whole library?





To export the structure from a nominated folder, use this script:


set dest to "/Users/me/Desktop/photos-Albums/" as POSIX file as text -- the destination folder (use a valid path)

tell application "Photos"
      set thisFolder to folder "some unique name" -- the nominated folder
      my exportAlbumsFromThisFolder(thisFolder, dest)
end tell

on exportAlbumsFromThisFolder(thisFolder, f) -- parameters of this handler:  the folder in "Photos",  the folder in the Finder
      tell application "Photos"
            repeat with thisAlbum in (get albums of thisFolder) --  albums of this folder
                  set tFolder to (f & (get name of thisAlbum))
                  my makeFolder(tFolder) -- create a folder named (the name of this album) in dest
                  with timeout of 600 seconds
                        export (get media items of thisAlbum) to (tFolder as alias) without using originals
                  end timeout
            end repeat
          
            -- recursively descends the folder tree, because the loop call this handler
            repeat with thisSubFolder in (get folders of thisFolder) -- sub-folders in this folder
                  set tFolder to f & (get name of thisSubFolder) & ":"
                  my makeFolder(tFolder) -- create a folder named (the name of this sub-folder) in dest
                  my exportAlbumsFromThisFolder(thisSubFolder, tFolder) -- call this handler
            end repeat
      end tell
end exportAlbumsFromThisFolder

on makeFolder(tPath)
      do shell script "mkdir -p " & quoted form of POSIX path of tPath
end makeFolder


----

lloydfromchristchurch wrote:



Also is it possible to rename the photos to run in a consecutive number range starting at "1" for each album as the photos are sorted in each album?




To rename the photos, use this script:


set dest to "/Users/me/Desktop/photos-Albums/" as POSIX file as text -- the destination folder (use a valid path)

tell application "Photos"
      set thisFolder to folder "some unique name" -- the nominated folder
      my exportAlbumsFromThisFolder(thisFolder, dest)
end tell

on exportAlbumsFromThisFolder(thisFolder, f) -- parameters of this handler:  the folder in "Photos",  the folder in the Finder
      tell application "Photos"
            repeat with thisAlbum in (get albums of thisFolder) --  albums of this folder
                  set tFolder to (f & (get name of thisAlbum))
                  my makeFolder(tFolder) -- create a folder named (the name of this album) in dest
                  with timeout of 600 seconds
                        export (get media items of thisAlbum) to (tFolder as alias) without using originals
                  end timeout
                  my renameFiles(get filename of media items of thisAlbum, tFolder)
            end repeat
          
            -- recursively descends the folder tree, because the loop call this handler
            repeat with thisSubFolder in (get folders of thisFolder) -- sub-folders in this folder
                  set tFolder to f & (get name of thisSubFolder) & ":"
                  my makeFolder(tFolder) -- create a folder named (the name of this sub-folder) in dest
                  my exportAlbumsFromThisFolder(thisSubFolder, tFolder) -- call this handler
            end repeat
      end tell
end exportAlbumsFromThisFolder

on makeFolder(tPath)
      do shell script "mkdir -p " & quoted form of POSIX path of tPath
end makeFolder

on renameFiles(namesList, f) --rename  starting at 1, the order is the sorted photos in the album
      set tCount to count namesList
      set thisFolder to f as alias
      tell application "System Events"
            repeat with i from 1 to tCount
                  try
                        set thisFile to file (item i of namesList) of thisFolder
                        set theExt to name extension of thisFile
                        set name of thisFile to ("" & i & "." & theExt)
                  on error number n
                        if n = -1728 then -- no file with this name , maybe a file with the same name (Photos append  " (1)"  to the filename)
                              set baseName to text 1 thru -((count theExt) + 2) of (item i of namesList) -- name without the extension
                              repeat with j from 1 to 5
                                    set tName to (baseName & " (" & j & ")." & theExt)
                                    if exists (file tName of thisFolder) then
                                          set name of file tName of thisFolder to ("" & i & "." & theExt)
                                          exit repeat
                                    end if
                              end repeat
                        end if
                  end try
            end repeat
      end tell
end renameFiles

Oct 24, 2016 12:51 PM in response to Fardilha

This is awesome. I used to use Phoshare but it broke after the migration to Photos. This has got me going again.


I have used your script with a couple of the tweaks here to sort alphabetically and adit the timeout since I do large batches at once.


To avoid the duplicate photos when you export an album a second time, is there a way to tell it to overwrite photos rather than putting (1) versions, or maybe more crudely to delete the destination folder before starting?

Oct 25, 2016 9:03 AM in response to barnabybarnaby

Hi,

barnabybarnaby wrote:




To avoid the duplicate photos when you export an album a second time, is there a way to tell it to overwrite photos rather than putting (1) versions, or maybe more crudely to delete the destination folder before starting?


It's not possible to overwrite files with the export command.

So, to delete the photos before the export command , replace the makeFolder() handler in your script by this:

on makeFolder(tPath)
    try -- if the folder exists then delete the photos in the folder
        tell application "System Events" to delete files of folder tPath -- remove files in this folder (the name of the album)
    end try
    do shell script "mkdir -p " & quoted form of POSIX path of tPath --  If the folder does not exist then create folder
end makeFolder


If you want to delete all folders in the destination folder, use this:

set dest to "/Users/me/Desktop/photos-Albums/" as POSIX file as text -- the destination folder (use a valid path)  
tell application "System Events" to delete folders of folder dest -- remove folders (albums) in the destination folder

Dec 24, 2016 12:17 PM in response to josepvr

Sure. Disclaimer though. I'm not a programmer and I'm new to Apple so...... Couldn't get the text to paste right so I'm pasting as an imaged. Sorry. I'm sure there arm better and easier ways to do this, but these worked for me.


This first one just exports a list of all the albums to a file. I migrated from iPhotos to Photos so the possibility of duplicate album names existed and that could potentially create issues when exporting programmatically. I was able to use the export of this to review in excel and then adjust album names as necessary to eliminate duplicates.

User uploaded file

This next one is just a slight modification to the original from Jacques. It just puts the album list in alphabetical order before letting you chose. I've used this one to export over 240 albums containing over 35,000 photos with no issues. Takes a while, but works well.


User uploaded file

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

export same albums from Photos

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.