Compare two lists and sort one according to the other

As a book designer I often have to deal with folders of images (sorted alphabetically) and dbases, excel sheets or whatever sorted on - for example - year of production.
This script gives you the possibility to compare and sort the input (list of images in a folder) with the necessary order of the output (pages with images). All based on unique filenames/ID-numbers.

--Select a text file sorted on another field then the ID-number. In this example: the year.
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.074 [tab] blahblah, 1994.
--AC.1.0395.073 [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 some images." with multiple selections allowed)

--piclist looks like (alphabetical):
--{"AC.1.0196.144.eps", "AC.1.0395.073-det.eps", "AC.1.0395.074.eps"}


--Create the picture list (to get the clean ID-numbers out of the filenames [without extensions or suffixes])
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. This part goes through the text file. 
--When the first part matches with an item of oldPicList it's placed in the newPicList.
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"}

{picList, oldPiclist, newPiclist}