1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
on min(x, y)
if x ≤ y then
return x
else
return y
end if
end min
set TempFolderPath to (path to downloads folder from user domain) as string
set TempFolderName to "PhotoExportTemp"
set TempFolder to TempFolderPath & TempFolderName & ":"
set PhotosBatchNumber to 100
-- Message to tell to the user to select photos to export in Photos app
display dialog "Aller dans l'application Photos pour selectionner les photos ou vidéos à exporter.
Lorsque c'est fait, cliquer sur Continuer.
A noter : Les éléments sont exportés par lots de " & PhotosBatchNumber & ".
" buttons {"Quitter", "Continuer"} default button "Continuer" cancel button "Quitter" with icon 2
-- Select the destination folder in which export photos
set TopFolderPath to choose folder with prompt "Selectionner le dossier dans lequel seront exportées les photos :"
-- get the list of selected pictures in Photos app
tell application "Photos" to set SelectedPhotos to get selection
-- Update the initial progress bar information
set NumberOfPhotos to length of SelectedPhotos
set progress total steps to NumberOfPhotos
set progress completed steps to 0
set progress description to "Export en cours..."
set progress additional description to "Préparation à l'export"
set PicProcessed to 1
-- Creation of a temp folder (no permission to export directly to TopFolderPath)
tell application "Finder"
if not (folder (TempFolder) exists) then
make new folder in TempFolderPath with properties {name:TempFolderName}
else
try
do shell script "rm -Rf " & (POSIX path of TempFolder) & "*"
end try
end if
end tell
-- Loop by Batch of PhotosBatchNumber photos
set FirstItem to 1
set LastItem to min(PhotosBatchNumber, NumberOfPhotos)
set ContinueLoop to 1
repeat while ContinueLoop = 1
set progress additional description to "Export des éléments " & FirstItem & " à " & min(LastItem, NumberOfPhotos)
set BatchPhoto to items FirstItem thru min(LastItem, NumberOfPhotos) of SelectedPhotos
tell application "Photos" to export BatchPhoto to alias (TempFolder) with using originals
set progress additional description to "Copie des fichiers sur le répertoire destination..."
tell application "System Events" to set Files_list to get the name of every disk item of alias (TempFolder)
set item_count to (get count of items in Files_list)
repeat with i from 1 to item_count
set the_properties to ""
set the_item to item i of the Files_list
set the_item to ((TempFolder & the_item) as string) as alias
tell application "System Events" to set file_info to get info for the_item
set File_name to displayed name of file_info
set theDate to modification date of file_info
-- Creation of Destination folder
-- convert date to yyyy-mm-dd
set SY to (year of theDate) as string
set SM to text -2 thru -1 of ("0" & ((month of theDate) as integer))
set SD to text -2 thru -1 of ("0" & ((day of theDate) as string))
set DestFolderName to SY & "-" & SM & "-" & SD -- DestFolder = folder "date"
set Destfolder to quoted form of ((POSIX path of TopFolderPath) & DestFolderName)
do shell script "[[ -d " & Destfolder & " ]] || " & "mkdir " & Destfolder
set PathFileName to quoted form of (POSIX path of TempFolder & File_name)
do shell script "mv " & PathFileName & " " & Destfolder
set progress additional description to "Copie de l'image " & PicProcessed & " sur " & NumberOfPhotos
set PicProcessed to PicProcessed + 1
set progress completed steps to PicProcessed
end repeat
set FirstItem to FirstItem + PhotosBatchNumber
set LastItem to LastItem + PhotosBatchNumber
if FirstItem > NumberOfPhotos then
set ContinueLoop to 0
end if
end repeat
do shell script "rm -Rf " & (POSIX path of TempFolder)
display dialog (NumberOfPhotos as string) & " Fichier(s) exportée(s)" buttons {"Ok"} default button 1 |
Partager