Bolish

Q: iPhoto - Automator Import Script Improvements

Hi All,

 

I'm mainly working on Lightroom but uses iPhoto to get a better integration into OS X.

My main issue was syncing both librairies and I came to this with an automator script that I'm proud about. I hope it could help some guys also.

I will detail my script below, but I basically have a Lightroom jpegs export into finder folders and an applescript that import them into iPhoto with correct album name.

I have 3 ideas to improve that workflow but didn't manage to script it.

 

1) First improvement - don't copy files during import to saves space.

For now, iPhoto is copying the files to the library during import.

I want to improve this script by not copying the files into iPhoto library during import but I didn't manage to do it.

I tried to uncheck the tick box "copy the files to iPhoto library" but it didn't works. Import works but files still copied into iPhoto library...

So, I'm struggling with HD space because I've the photos twice on my hard disk (once in folder, once in iPhoto library)

 

2) Make a daily check of my photo folder content to launch the script automatically during night if there were some changes.

Something like :

If photofolder content (qty of files) is different than the day before, launch the import process

Else

End if

 

3) Don't import hidden folder

The "dispense item incrementally" is also scanning hidden folder (e.g : 'album data.xml' folder) that I didn't want to appear into iPhoto library.

I didn't find any option to not scan hidden folders right now.

 

My workflow in Automator :

 

Delete current iPhoto library

Create new one

List photos folder with "dispense folder incrementally"

Set folder name as a variable

Import this folder content to new iPhoto album with the above variable as album name.

Loop until dispense folder incrementally is done

 

Hoping that my post could support some guys who need that kind of workflow and hoping you guys could support my needs!

 

Regards

Posted on Jun 28, 2014 11:40 AM

Close

Q: iPhoto - Automator Import Script Improvements

  • All replies
  • Helpful answers

Previous Page 2
  • by Bolish,

    Bolish Bolish Apr 11, 2015 12:29 PM in response to Jacques Rioux
    Level 1 (0 points)
    Photos for Mac
    Apr 11, 2015 12:29 PM in response to Jacques Rioux

    Hi Jacques,

     

    It works great. Thanks. I don't know if you are familiar with the new "photos" app included into last Yosemite release but since yesterday, I tried to specify the script to make it works with the new Photos app, I hoped it could work by replacing each "iPhoto" by "Photos" everywhere but I'm facing an issue on this line :

     

    set albNames to name of albums whose its type is regular album and name is not imAlb


    The error highlights the "regular album"

    "Syntax error" End of line, etc...but class name found.

    In french : " fin de ligne, etc....prevu, mais nom de classe trouvé"

     

    See entire code blow :

    -------------------------------------------------------------------------------- -------------------------------------------

     

    property oldModifDates : {} -- The value set by a property definition is not reset each time the script is run; instead, it persists until the script is recompiled.   

    property oldFolderNames : {}

     

    property firstRun : true

     

    display dialog "Your MAC wants to update iPhoto library, do you want to continue?" with title "iPhoto Import"

    --- if you press Cancel in the dialog, this application or this script will stop immediately. 

     

     

     

    if firstRun then -- ** reset iPhoto ** 

     

      display dialog "iPhoto wants to delete current library before to proceed new import, do you still want to continue?" with title "iPhoto Import"

      --- if you press Cancel in the dialog, this application or this script will stop immediately. 

     

      resetiphoto()

     

     

    else -- give the possibility to reset iphoto librairay

     

     

      set askToReset to "Do you wish to reset your iPhoto Library before to proceed new import?"

      set tempVar to display dialog askToReset buttons {"No", "Yes"}

      set boutonAppuye to button returned of tempVar

     

      if boutonAppuye is "Yes" then

     

      set oldModifDates to {} -- The value set by a property definition is not reset each time the script is run; instead, it persists until the script is recompiled.   

      set oldFolderNames to {}

     

      set firstRun to true

     

      resetiphoto()

      end if

     

     

    end if

     

    set watchFolder to "/Users/Shared/Images partagées" -- remove 'pathToWatchFolder' in this line and drag/drop your folder between the two double quote.    

    set newFolderNames to {}

    set newModifDates to {}

     

    -- get the subfolders in source folder (at the root only)   

    tell application "System Events"

      repeat with f in (get folders of folder watchFolder whose visible is true)

      tell f

      set tName to name

      set modifDate to modification date

      set end of newFolderNames to tName -- add this name to new list 

      set end of newModifDates to modifDate -- add this date to new list 

      set doIt to tName is not in oldFolderNames

      if not doIt then -- this name is in the old list of folderNames  then check modif date 

      set oldMoDate to my getOldModifDate(tName) -- get the index of this name in the list of names, this subRoutine return the old modif date at same index in the dates list 

      set doIt to oldMoDate is not modifDate -- compare the date , these dates contains the time 

      end if

      if doIt then -- different modification dates or this name is not in old list   

      set jpegs to (POSIX path of files whose type identifier is "public.jpeg") -- get JPEG's file only    

      my import_To_iPhoto(tName, jpegs) -- update album   

      end if

      end tell

      end repeat

    end tell

    if newFolderNames is not {} then -- to synchronize regular album, this do nothing on smart album and folder album in iPhoto   

      set oldModifDates to newModifDates -- update list    

      set oldFolderNames to newFolderNames -- update list   

      tell application "Photos"

      set imAlb to name of last import album

      set albNames to name of albums whose its type is regular album and name is not imAlb

      end tell

      repeat with i in albNames -- check  the name of this album with the names of the subFolders   

      set alb_Name to contents of i

      if alb_Name is not in newFolderNames then

      --  delete this album because the subfolder no longer exists in the whole Photo folder.   

      tell application "Photos"

      remove (photos of album alb_Name) from photo library album -- remove photos    

      remove album alb_Name -- remove empty album   

      end tell

      end if

      end repeat

    end if

     

    on import_To_iPhoto(t_Name, theseFiles)

      tell application "Photos"

      repeat while importing is true -- wait if importing     

      delay 2

      end repeat

      if exists album t_Name then

      set alb to album t_Name

      remove (photos of alb) from photo library album -- delete photos of this album in the master library (put the photos in the trash album)   

      else

      set alb to new album name t_Name

      end if

      import from theseFiles to alb without force copy -- 'without force copy': use the advanced preference of iPhoto     

      end tell

    end import_To_iPhoto

     

    on getOldModifDate(t)

      set tc to count oldFolderNames

      repeat with i from 1 to tc

      if item i of oldFolderNames = t then return item i of oldModifDates

      end repeat

    end getOldModifDate

     

    on resetiphoto()

      set firstRun to false

      quit application "Photos"

      do shell script "sleep 4"

      set p to path to preferences folder as text

      tell application "System Events"

      tell property list file (p & "com.apple.Photos.plist") to set lib_loc to value of property list item "LibraryPath"

      end tell

      set tPath to quoted form of lib_loc

      do shell script "rm -fr " & tPath & ";cp -fpR ~/Pictures/'Empty Photos Library.photoslibrary' " & tPath -- , the current library will be replaced by the empty library package

     

      activate application "Photos" -- open the empty library

    end resetiphoto

     

    say "iPhoto import script is completed." using "victoria"

     

    --display dialog "iPhoto import script is completed." buttons {"Ok"}

     

     

     

    -------------------------------------------------------------------------------- -----------------------

  • by olivev,

    olivev olivev Aug 20, 2015 5:32 PM in response to Bolish
    Level 1 (0 points)
    Aug 20, 2015 5:32 PM in response to Bolish

    No solution ?

  • by Jacques Rioux,

    Jacques Rioux Jacques Rioux Aug 21, 2015 6:11 AM in response to olivev
    Level 4 (3,418 points)
    Mac OS X
    Aug 21, 2015 6:11 AM in response to olivev

    Hi,

     

    olivev wrote:

     

    No solution ?

     

    The term album does not work, you must use container.

    The term photo does not work, you must use media item.

     

    It is not possible to filter by type since this property does not exist.

    So you need to include a list of names in the script to exclude folder albums ans smart albums.

    Example :

    set excludedAlbums to {"Vacance", "Événements iPhoto", "Favorites"}

    if newFolderNames is not {} then -- to synchronize album

          set oldModifDates to newModifDates -- update list   

          set oldFolderNames to newFolderNames -- update list  

          tell application "Photos"

                set imAlb to name of last import album

                set albNames to name of containers whose its name is not imAlb

                repeat with i in albNames -- check  the name of this album with the names of the subFolders 

                      set alb_Name to contents of i

                      if alb_Name is not in excludedAlbums and alb_Name is not in newFolderNames then

                            --  delete this album because the subfolder no longer exists in the whole Photo folder.

                            set thisAlbum to container alb_Name

                            --delete media items of thisAlbum -- not possible

                            --delete thisAlbum -- not possible

                      end if

                end repeat

          end tell

    end if

    --------------------

     

    It's not possible to delete an album or a photo, because delete and remove commands no longer exists in the AppleScript dictionary of Photos, maybe in the future version of Photos.

    This may be possible from the photo database ("Library.apdb") by using the sqlite3 command in a shell script.

     

    -------

    This thread is a question for iPhoto, if you have a question for the "Photos" application, start a new thread.

Previous Page 2