The Apple Photos application leaves a lot to be desired. Its simplistic approach is often counter productive to advanced users. Something that drives me nuts is the inability to import a folder full of images directly into Photos while maintaining the folder name as a an album in Photos.
I often stockpile photos from my DSLR and family iPhones. I create folders with event names to organize my photos. I then upload my pictures to an online photo repository and import them into Photos.
The following AppleScript helps to automate importing folders as albums in Photos. Simply run the script and select your folders… Thanks to codez for this awesome script!
ImportPhotoFolders
[sourcecode language=”plain”]on runset 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
to replaceText(someText, oldItem, newItem)
(*
replace all occurances of oldItem with newItem
parameters – someText [text]: the text containing the item(s) to change
oldItem [text, list of text]: the item to be replaced
newItem [text]: the item to replace with
returns [text]: the text with the item(s) replaced
*)
set {tempTID, AppleScript’s text item delimiters} to {AppleScript’s text item delimiters, oldItem}
try
set {itemList, AppleScript’s text item delimiters} to {text items of someText, newItem}
set {someText, AppleScript’s text item delimiters} to {itemList as text, tempTID}
on error errorMessage number errorNumber — oops
set AppleScript’s text item delimiters to tempTID
error errorMessage number errorNumber — pass it on
end try
return someText
end replaceText
on importEachSubFolder(aFolder, parentFolder)
tell application "Finder"
set albumName to (name of aFolder as text)
set subFolders to every folder of aFolder
end tell
— set albumName to replaceText(albumName, "_", space) –if you want to change a special character (such as _ ) to spaces in Album names, uncomment this line
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 (30 * 60) 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", "M4V", "m4v", "MPG", "mpg", "BMP", "bmp", "TIF", "tif", "AVI", "avi", "PSD", "psd", "ai", "AI", "orf", "ORF", "nef", "NEF", "crw", "CRW", "cr2", "CR2", "dng", "DNG", "PEF"}
with timeout of (30 * 60) seconds
tell application "Finder" to set theFiles to every file of aFolder whose name extension is in extensionsList
end timeout
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[/sourcecode]
Copy the above script into the Script Editor ( /Applications/Script Editor.app ) and enjoy the bliss.