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 albumalb_Name) fromphoto library album-- remove photos
removealbumalb_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) fromphoto 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
importfromtheseFilestoalb without force copy-- 'without force copy': use the advanced preference of iPhoto
end tell
end import_To_iPhoto
on getOldModifDate(t)
set tc to countoldFolderNames
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
quitapplication "Photos"
do shell script "sleep 4"
set p to path topreferences folderastext
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
activateapplication "Photos" -- open the empty library
end resetiphoto
say "iPhoto import script is completed." using "victoria"
--display dialog "iPhoto import script is completed." buttons {"Ok"}
-------------------------------------------------------------------------------- -----------------------