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", "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", HEIC"}
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:
For this folder configuration on the hard drive: You'll get this configuration in Photos:
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.