Я сделал следующий AppleScript для экспорта фотографий в каталоги с именами по датам (ГГГГ-ММ-ДД):
set TempFolderPath to (path to downloads folder from user domain) as string
set TempFolderName to "PhotoExportTemp"
set TempFolder to TempFolderPath & TempFolderName & ":"
-- 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" 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 PicsList to get selection
-- Update the initial progress bar information
set theImageCount to length of PicsList
set progress total steps to theImageCount
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
repeat with aPhoto in PicsList
set progress additional description to "Export de l'image " & PicProcessed & " sur " & theImageCount
delay 1
-- export photos in TempFolder
tell application "Photos"
set SName to filename of aPhoto
set theDate to date of aPhoto
export {aPhoto} to alias (TempFolder) with using originals
end tell
-- 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
-- copy picture from TempFolder to Destination forlder
set TempSName to (do shell script "echo " & quoted form of SName & " | cut -d. -f1")
set TempFileName to quoted form of (POSIX path of TempFolder & TempSName) & "*"
do shell script "cp -p " & TempFileName & " " & Destfolder
-- remove temp file
try
do shell script "rm -f " & TempFileName
end try
set PicProcessed to PicProcessed + 1
set progress completed steps to PicProcessed
end repeat
do shell script "rm -Rf " & (POSIX path of TempFolder)
display dialog (theImageCount as string) & " Fichier(s) exportée(s)" buttons {"Ok"} default button 1
У меня проблема со следующей частью:
tell application "Photos"
set SName to filename of aPhoto
set theDate to date of aPhoto
export {aPhoto} to alias (TempFolder) with using originals
end tell
Это работает, когда я запускаю его для 10 фотографий, но если я пытаюсь запустить его для 500 фотографий, у меня случайно появляется следующая ошибка во время выполнения:
Ошибка в фотографиях, соединение недействительно -609
Я пытался установить задержку на 1 раньше, но у меня все еще есть ошибка.
Что я могу сделать, чтобы избежать этой ошибки?
Примечание: я использую временная папка, потому что она всегда терпела неудачу, когда я пытаюсь использовать команду экспорта в сетевую папку (на моем NAS).