I have an applescript for renaming files based on names provided by a numbers spreadsheet.
Each image has three different sizes, each size in one folder. So there is
/50/exportedImage-01.svg
/33/exportedImage-01.svg
/25/exportedImage-01.svg
The script works totally fine and does what it should do, BUT it is painfully slow and stops at 50+ files. Because I have several hundred files to rename, the question is:
is there any way to alter the script to make it more efficient/powerful?
The workflow is as follows:
- read the numbers file - new names (featuredImage) in column B, old names (exportedImage) in column C
- loop through files in first folder and rename them according to column B
- loop through files in second folder and rename them according to column B
- loop through files in third folder and rename them according to column B
Here is what I got so far:
set numbersFile to choose file with prompt "Choose the Numbers file" of type {"numbers", "XLS7", "XLS8", "XLSX"}
set theFolder to choose folder with prompt "Choose the folder 50 containing the files to rename"
--get a list of the old and the new filenames
set exportedImage to {}
set featuredImage to {}
tell application "Numbers"
open numbersFile
tell table 1 of sheet 1 of document 1
--tell document 1
--tell sheet 1
repeat with i from 1 to row count
if value of cell ("C" & i as text) > "" then
set exportedImage to exportedImage & value of cell ("C" & i as text)
set featuredImage to featuredImage & value of cell ("B" & i as text)
else
exit repeat
end if
end repeat
--end tell
end tell
close window 1
end tell
--loop through the files in folder 50 and rename them
tell application "Finder"
repeat with k from 1 to (count of (get every item of theFolder))
repeat with i from 1 to count of exportedImage
if (name of item k of theFolder) as text = (item i of exportedImage) as text then
set name of (item k of theFolder) to (item i of featuredImage as text)
end if
end repeat
end repeat
end tell
--loop through the files and rename them 33
set theFolder to choose folder with prompt "Choose the folder 33 containing the files to rename"
tell application "Finder"
repeat with k from 1 to (count of (get every item of theFolder))
repeat with i from 1 to count of exportedImage
if (name of item k of theFolder) as text = (item i of exportedImage) as text then
set name of (item k of theFolder) to (item i of featuredImage as text)
end if
end repeat
end repeat
end tell
--loop through the files and rename them 25
set theFolder to choose folder with prompt "Choose the folder 25 containing the files to rename"
tell application "Finder"
repeat with k from 1 to (count of (get every item of theFolder))
repeat with i from 1 to count of exportedImage
if (name of item k of theFolder) as text = (item i of exportedImage) as text then
set name of (item k of theFolder) to (item i of featuredImage as text)
end if
end repeat
end repeat
end tell
I would like to stick with applescript, because this script is part of a bigger automator workflow.
Any help appreciated, thanks!