Я потратил некоторое время, чтобы закончить свой первый комментарий.Позвольте мне объяснить, как вы можете использовать команду 'find'.
Мы ищем имя файла "ExportedImage1.svg" в папке "/ Users / Document / Folder50 /".Команда оболочки: find /Users/Document/Folder50/ExportedImage1.svg
Команда «Найти» может быть улучшена с помощью функции «-exec».Для каждого найденного файла -exec будет применять команду сразу после.В exec следующая команда может использовать {}, что означает файл, найденный в команде find.наконец, но не в последнюю очередь, синтаксис требует ';'в конце.
Пример: find path / file.svg -exec mv {} path / newName.svg ';'
Поиск пути / file.svg и, если он найден,он применяет команду mv (переместить или переименовать) к этому файлу {} с новым значением path / newName.svg.
В приведенном ниже сценарии я использовал Excel (потому что у меня нет номеров!), но выможете легко настроить первый блок скрипта, чтобы использовать ваши номера.
Также я изменил вашу логику, выполнив цикл по всей строке данных Excel (второе двоеточие = экспортированное изображение).Внутри этого цикла для каждой строки изображения / Excel я перебираю 3 выбранные вами папки (25, 33 и 50).внутри этого цикла я ищу файл в папке и, если он найден, я изменяю имя, используя первый двоеточие файла Excel (FeaturedImage).
Я предполагаю, что расширения файлов всегда '.svg'
-- you must replaced that block by your Numbers block
set numbersFile to choose file with prompt "Choose the Numbers file" of type {"numbers", "XLS7", "XLS8", "XLSX"}
tell application "Microsoft Excel"
-- my Excel file is made of column B=FeaturedImage (will be new file names) and column C=ExportedImage (current file name)
-- I assume that name in files have no extension '.svg'
open numbersFile
tell active sheet to set myData to value of used range
close window 1
-- myData is list of rows: each item is a list made of 2 values : value in col B and value in col C
end tell
-- select the 3 folders
set folder50 to choose folder with prompt "Choose the folder 50 containing the files to rename"
set folder33 to choose folder with prompt "Choose the folder 33 containing the files to rename"
set folder25 to choose folder with prompt "Choose the folder 25 containing the files to rename"
-- build a list of the 3 folders
set myFolders to {POSIX path of folder50}
set myFolders to myFolders & {POSIX path of folder33}
set myFolders to myFolders & {POSIX path of folder25}
repeat with myRow in myData -- loop through all data rows
repeat with aFolder in myFolders -- loop through folders : 25, 33, 50
-- search file name = item 2 of myRow (=ExportedImage) in folder 50 and if find, rename to item 1 of myRow
set curPath to quoted form of (aFolder & (item 2 of myRow) & ".svg") -- the complete path/name to search
set newPath to quoted form of (aFolder & (item 1 of myRow) & ".svg") -- the complete path/name to replace/rename
try -- to avoid error in case file not found in the folder
do shell script "find " & curPath & " -exec mv {} " & newPath & " ';'"
end try
end repeat -- next folder 25, 33, 50
end repeat -- next data row
Оптимизация циклов и использование 'find - exec' делают этот скрипт намного быстрее, чем ваш !!