Hi all,
I had to sort a list (of a folder with images; selected by the user) based on the order of a text file (containing unique numbers and specs; 360 lines).
The images should be placed in the order of the text file; the file names of the corresponding images are not in the same order, but alphabetically.
Then I came up with this, which works fine for me. Now I was thinking if this is a reliable way to do, or if there is a faster possibility. (Just to learn some more about Applescript.)
Thanks to anyone looking at it.
kjeld
PS: The script is an extract of a bigger one. If it’s necessary to post the complete one, let me know.
set specsFile to (choose file with prompt "Select the text file with specifications.")
set thisfile to read file (specsFile as string) using delimiter {return}
--Thisfile looks like (sorted on the year of production):
--AC.1.0395.073 [tab] blahblah, 1994.
--AC.1.0395.074 [tab] blahblah, 1996.
--AC.1.0196.144 [tab] blahblah, 1998.
--etc.
--Select images of the chosen folder.
set thefolder to (choose folder with prompt "Select the folder with images.")
set folderList to (list folder (thefolder as alias) without invisibles)
set picList to (choose from list folderList with prompt "Select " & numPicBox & " images." with multiple selections allowed)
--piclist looks like:
--{"AC.1.0196.144.eps", "AC.1.0395.073.eps", "AC.1.0395.074.eps"}
--Create new picture list (without extensions)
set oldPiclist to {}
repeat with n from 1 to count of picList
set thefile to ((characters 1 thru 13 of item n) of picList as string)
set end of oldPiclist to thefile
end repeat
--> --{"AC.1.0196.144", "AC.1.0395.073", "AC.1.0395.074"}
--Sort oldPicList according to thisFile
set newPiclist to {}
repeat with i from 1 to count of thisfile
set thisImage to ((characters 1 thru 13 of item i) of thisfile as string)
if thisImage is in oldPiclist then
set end of newPiclist to thisImage
end if
end repeat
--> --{"AC.1.0395.073", "AC.1.0395.074", "AC.1.0196.144"}