retrieve page numbers for index

I have an index of listings that need page numbers.

I need to be able to enter a 5 digit number and have the page number that it’s on displayed to me.

I have some of the script below, but I know this will not do what I want.

set ChosenFile to choose file with prompt "Select file to lift numbers from." of type "TEXT"
open for access ChosenFile
set TextRun to read ChosenFile
close access ChosenFile

set CountWord to count (get every word of TextRun)
set NumList to {}

repeat with PointWord from 1 to CountWord
	set CurrWord to get word PointWord of TextRun
	if CurrWord = "#" and PointWord < CountWord then
		set end of NumList to (get word (PointWord + 1) of TextRun)
	end if
end repeat

set SourceLoc to choose folder with prompt "Where is the list of numbers located?"

set DestLoc to choose folder with prompt "Select folder to transfer page numbers to."

set CountItem to count every item in NumList
repeat with PointItem from 1 to CountItem
	try
		set ItemNo to get item PointItem of NumList
		set TargetFile to (SourceLoc as text) & (ItemNo as text)
		tell application "Finder"
			duplicate file TargetFile to folder DestLoc
		end tell
	end try
end repeat

display dialog "Script finished."

Hi,

nice script, but what (the h***) is in ChosenFile :wink:

Stefan, thanks for your help.

The list of listing numbers are in ‘ChosenFile’

The lest looks like this…

12345
96754
23845

…and so on.

There are about 2 thousand 5-digit numbers to find the page number for.

Hm, and where does the # come from?

All jokes aside: The more information we get, the more help you (could probably) get

The ‘#’ is what I used to identify the numbers.

When the script cycles through, it can select the numbers with ‘#’ in front of them.

I did this, because most of the numbers begin with ‘1’, although not all of them. By putting in ‘#’ it can grab all the numbers.

So, the list actually will look like this…

#12345
#36465
#93645