Finding files from a list in a text file

can someone help me with this script.
Its a script that reads through each paragraph of a text file and searches for a filename with the same name as each paragraph.
i.e.
paragraph 1 reads: 123456
finder looks for a file called 123456
and so on…

here is what i have so far…

tell document "test.txt" of application "TextEdit"
	set numParagraphs to count every paragraph
	repeat with n from 1 to numParagraphs
		copy paragraph n to currentGraph
		-- display dialog currentGraph
		
		tell application "System Events"
			set myPath to ":Users:Me:Desktop:" as string
			tell process "Finder"
				set value of text field 1 of group 1 of tool bar 1 of window 1 to currentGraph -- stops right here for some reason!
			end tell
		end tell
		
	end repeat
end tell

the script doesnt work completely

this however does work by changing the line to:
set value of text field 1 of group 1 of tool bar 1 of window 1 to “Some Text”

this doesn’t, but i need to pass the variable into the text field
set value of text field 1 of group 1 of tool bar 1 of window 1 to currentGraph

the script is not complete - I intend on narrowing down the search to search for only image files and then copying the first result to a specified directory. Then proceeding on down the list.

Model: Dual 2 GHz G5 w/ 8 gigs of RAM
AppleScript: 1.10.7
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

Okay lets get some more info first to make sure we aren’t making this overly complicated…

So does your text file look like this?

Is it rich text or plain text? If it’s rich text we’re going to have a much easier time and there is no need to involve Text Edit.

Do the files you’re looking for contain those string? Or are they named exactly?

Will the files be in a particular place? In the users home folder somewhere for example? Or could they be anywhere on the HD?

Give us more detailed info please =)

I’m afraid that this is a rather large leap from where you are to where you want to be, but finding is never easy. Assuming that you want the paths to the files as aliases so you can do something with them, and that you have a list of file names, one per line, called test.txt (which is text, not rtf) on your desktop, and that the file names are complete in that they include extensions if they show in the Finder, then this is an efficient way to find them:


-- you don't have to use an application to read a text file; AppleScript can do it.
set tList to paragraphs of (read alias ((path to desktop as text) & "test.txt"))
-- limit the search (in this case to the user's pictures folder)
set tSearchFolder to path to pictures folder
-- the search will be done by a shell function so we need a posix path (a unix path)
set pSF to POSIX path of tSearchFolder
set tPaths to {}
repeat with aFile in tList -- a form that's faster because you don't have to count the list
		try
		set end of tPaths to POSIX file (do shell script "mdfind -onlyin " & pSF & space & quoted form of aFile) as alias
	on error -- no file by that name was found in the searchfolder.
		set end of tPaths to aFile & " N/A"
	end try
end repeat
tPaths -- a list of the files whose names were in the original list or the name followed by N/A if not found.

Oh boy here we go again Adam, mdfind vs find…

Just kidding :smiley:

Ahh yes, James - but the Pictures folder is spotlighted. If his files are on a server, however, then we’ll have to think of another way. Problem is that the original poster didn’t tell us much about he wanted to do and the environment in which he wanted to do it.

Yeah, but you cheated =) Since he mentioned images you jumped to the pictures folder which works with mdfind.

Actually it’s pretty safe to just ignore me at the moment… I’m terrribly bored and on the train :frowning: But I’m getting 1mb downspeeds so it’s not too bad :smiley: (gotta love EVDO rev A)

Yah, possibly, but I did it in good faith - I know how to use mdfind and don’t know how to use find. :rolleyes:

I’m reading from a directory on our server. The items in the list just are not specific file names but just contain a portion of the file name. The files are all image files tiff or psd usually. The list can be rich text or plain, what ever I format it as.

Sorry I havent been more specific. What I’m trying to do is get the first paragraph, search a specific directory on my server, copy the first image that comes up to a folder on my desktop, proceed on to the next paragraph and do the same thing all over again. And, in a perfect world if the image is not found, log it to a file, and keep on truckin!

Hope this helps. Thanks everyone for your interest here.

I got my original script to return something :smiley: as long as I’m not passing a variable into text field 1 - but as soon as I try to set currentGraph into text field 1 it crashes. I think its trying to search for currentGraph literally and not finding the phrase currentGraph and crashing.