Apple Photos import with album name

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Apple Photos import with album name Sun May 15, 2016 7:22 am • by evansgo
Hello,

I can nearly do what I want with an apple script from https://discussions.apple.com/message/29200902#29200902 (code below)
But just to make it really fit my workflow I would like to have some Hazel magic as well.
What I would like is for Hazel to watch a folder, then when I export an album from Lightroom which will have a single album name containing a number of pictures, to run the script with the album name filled in, then when the script is complete to delete both the photos and the folder. Is this easy to achieve?
Thanks....

Code: Select all
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
evansgo
 
Posts: 2
Joined: Sun May 15, 2016 7:14 am

Re: Apple Photos import with album name Mon May 16, 2016 10:34 am • by Mr_Noodle
Hazel's "Import into Photos" action doesn't provide for album names created on the fly. If you want to use the script, you need to adapt it to work with Hazel. Search the in-app help as it gives all the details needed for that.
Mr_Noodle
Site Admin
 
Posts: 11877
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support