Currently Being Moderated

Import Folders of Image Files into Library as Albums

This Applescript was created by user code!z and published at Github: ImportPhotoFolders where you can download an already compiled and saved Applescript file.  With his permission I'm publishing the script here.

 

When run it will import selected folders of image files into your Photos library and create albums in the sidebar for each folder with the same name as the folder.

 

Open Script Editor and paste the following into its window:

on run

  set folderList to (choose folder with multiple selections allowed)

 

  tell application "Photos"

  activate

  delay 2

  end tell

 

  repeat with baseFolder in folderList

  importEachSubFolder(baseFolder, null)

  end repeat

end run

 

on importEachSubFolder(aFolder, parentFolder)

  tell application "Finder"

  set albumName to (name of aFolder as text)

  set subFolders to every folder of aFolder

  end tell

 

  if (count of subFolders) > 0 then

  set fotoFolder to createFotoFolder(aFolder, albumName, parentFolder)

 

  repeat with eachFolder in subFolders

  importEachSubFolder(eachFolder, fotoFolder)

  end repeat

  else

  set fotoFolder to parentFolder

  end if

 

  importFotos(aFolder, albumName, fotoFolder)

end importEachSubFolder

 

on importFotos(aFolder, albumName, parentFolder)

  set imageList to getImageList(aFolder)

  if imageList is {} then return

 

  set fotoAlbum to createFotoAlbum(albumName, parentFolder)

 

  tell application "Photos"

  with timeout of 600 seconds

  import imageList into fotoAlbum skip check duplicates no

  end timeout

  end tell

end importFotos

 

on createFotoFolder(aFolder, folderName, parentFolder)

  tell application "Photos"

  if parentFolder is null then

  make new folder named folderName

  else

  make new folder named folderName at parentFolder

  end if

  end tell

end createFotoFolder

 

on createFotoAlbum(albumName, parentFolder)

  tell application "Photos"

  if parentFolder is null then

  make new album named albumName

  else

  make new album named albumName at parentFolder

  end if

  end tell

end createFotoAlbum

 

on getImageList(aFolder)

  set extensionsList to {"jpg", "png", "tiff", "JPG", "jpeg", "JPEG", "PNG", "TIFF"}

  tell application "Finder" to set theFiles to every file of aFolder whose name extension is in extensionsList

 

  set imageList to {}

  repeat with i from 1 to number of items in theFiles

  set thisItem to item i of theFiles as alias

  set the end of imageList to thisItem

  end repeat

 

  imageList

end getImageList

 

Click on the Compile button to make sure it copied and can compile correctly.

 

   Highlight001.jpg

 

The script can be saved as an Applesciprt or, as I prefer, as an application.   When the executable file is saved double click on it to start the process.   You'll get this window:

 

ImportPhotoFolders001.jpg

 

Select the folder(s) to be imported and click on the Choose button.  The importing will begin immediately.  When completed you'll be taken to the Last Import album in Photos and a new album with the same name as the folder will have been created in the sidebar:

 

Photos001.jpg

 

Again thanks to user code!z for the script.


NOTE: 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

 

VERSION 2: user code!z updated his script to allow importing nested folders which results in nested folders and albums in Photos.  The update code is:

on run

  set folderList to (choose folder with multiple selections allowed)

 

  tell application "Photos"

  activate

  delay 2

  end tell

 

  repeat with baseFolder in folderList

  importEachSubFolder(baseFolder, null)

  end repeat

end run

 

on importEachSubFolder(aFolder, parentFolder)

  tell application "Finder"

  set albumName to (name of aFolder as text)

  set subFolders to every folder of aFolder

  end tell

 

  if (count of subFolders) > 0 then

  set fotoFolder to createFotoFolder(aFolder, albumName, parentFolder)

 

  repeat with eachFolder in subFolders

  importEachSubFolder(eachFolder, fotoFolder)

  end repeat

  else

  set fotoFolder to parentFolder

  end if

 

  importFotos(aFolder, albumName, fotoFolder)

end importEachSubFolder

 

on importFotos(aFolder, albumName, parentFolder)

  set imageList to getImageList(aFolder)

  if imageList is {} then return

 

  set fotoAlbum to createFotoAlbum(albumName, parentFolder)

 

  tell application "Photos"

  with timeout of 600 seconds

  import imageList into fotoAlbum skip check duplicates no

  end timeout

  end tell

end importFotos

 

on createFotoFolder(aFolder, folderName, parentFolder)

  tell application "Photos"

  if parentFolder is null then

  make new folder named folderName

  else

  make new folder named folderName at parentFolder

  end if

  end tell

end createFotoFolder

 

on createFotoAlbum(albumName, parentFolder)

  tell application "Photos"

  if parentFolder is null then

  make new album named albumName

  else

  make new album named albumName at parentFolder

  end if

  end tell

end createFotoAlbum

 

on getImageList(aFolder)

  set extensionsList to {"jpg", "png", "tiff", "JPG", "jpeg", "gif", "JPEG", "PNG", "TIFF", "GIF", "MOV", "mov", "MP4", "mp4", "MPG", "mpg", "BMP", "bmp", "TIF", "tif", "AVI", "avi", "PSD", "psd", "ai", "AI", "orf", "ORF", "nef", "NEF", "crw", "CRW", "cr2", "CR2", "dng", "DNG", "PEF"}

  tell application "Finder" to set theFiles to every file of aFolder whose name extension is in extensionsList

 

  set imageList to {}

  repeat with i from 1 to number of items in theFiles

  set thisItem to item i of theFiles as alias

  set the end of imageList to thisItem

  end repeat

 

  imageList

end getImageList

 

This code will produce the following:

 

For this folder configuration on the hard drive:                    You'll get the following configuration in Photos:

Test1.jpg           Test1a.jpg

 

For this folder configuration on the hard drive:                      You'll get this configuration in Photos:

Test2a.jpg            Test2.jpg

 

Again, thanks to code!z for his contribution of this 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.  Both versions will be downloaded by the same link.

Replies

Delete User Tip

Are you sure you want to delete this user tip?