AS, IDCS2: Relink to found existing link

I’m trying to write a script that will repeat through a files links to see if they arleady exist in a premade series of library subfolders. (ie. take link name, look in all folders for same, relink to found file path). Problem is I have know idea how to start. If I set a variable to the contents libraries subfolders it’s really only geting a giant list of files, I have no idea how to abstract the single file path whose name matches that of the IDCS2 link so I can have the app relink.

basic outline:


tell app "InDesign CS 2"
activate
tell active document
set theLink to every link
tell application "Finder"
			set theLibraryFolders to every folder in every folder in {"Volume1:ABC Art:ABC Color Art"}----file path to main library folder
			set theLibraryList to every file in theLibraryFolders
		end tell
repeat with i from 1 to count of theLink
			set theName to name of it
if exists theName in theLibraryList---???
---get stuck there, and I know the references won't work they're just lists
end if
end repeat
end tell
end tell

The purpose of this script is to link all graphics to a public library folder if possible.

Thoughts???

This should get you started:

set TheFolder to choose folder
tell application "Finder" to set FileNames to name of every file in TheFolder
tell application "Adobe InDesign CS2"
	activate
	tell active document
		set theLink to every link
		repeat with i from 1 to count of theLink
			if name of item i of theLink is in FileNames then
				--relink here
				
			end if
		end repeat
	end tell
end tell

You need to relink using the name and the path (TheFolder).

Thanks for the reply, the script you provided can get the list of available links and compare it to the links in the IDCS2 file fine, but it can’t relink them since it’s treating them as lists only (not file paths or alias’). I’m beginning to think I"ll need a repeat loop that goes link by link getting the name then searching the subfolders, which unfortunately will take longer.

I was in a bit of a hurry when I replied before and I don’t have access to ID at the moment. Your new path is going to be the name of your old link, which should have any extension attached to it if used, and your path. So you should be able to use:

set NewLink to (TheFolder as string)  & name of item i of theLink

as the new path to re-link the file. There may be a little finessing involved but the principle should work.

I think I’ve found it, it’s a coercion problem. When searching the list of files for the given file name the two don’t match up. So I have to coerce the file name in InDesign or the file list of Finder.

Thoughts?

The script I posted above should not have a problem with coercion of the file names, both are returned as strings. If you post the code that you are working with then I can look and see if I can help further.

If you are still working with the Finder routine that you posted earlier then the problem is that you are comparing the full file path from the Finder and not the name of the file while the name of the link is the file name without the file path. You could get around this by using text item delimiters, coercing the Library items to a string and then grabbing the last item of each to compare against. It is a bit more code and I don’t think that it is the way you want to go about it. Then again since you have sub-folders in your library folder my method would probably take some work as well since it assumes the file is in the library folder and not a sub folder of the library.

Here is the script I’m working with so far:


set oldDelims to AppleScript's text item delimiters
tell application "Finder"
	set TheFolder to choose folder
	set AppleScript's text item delimiters to ","
	set LinkList to every document file in every folder in TheFolder as string
	set thePaths to every text item of LinkList
	tell application "Adobe InDesign CS2"
		activate
		tell active document
			set theLink to every link
			repeat with i from 1 to count of theLink
				if name of item i of theLink is in thePaths then
					set theLinkName to name of item i of theLink
					set theNewPath to (text item of thePaths where exists theLinkName) as alias
					tell item i to relink to theNewPath
				end if
			end repeat
		end tell
	end tell
end tell
set AppleScript's text item delimiters to oldDelims

It seems to coerce fine but doesn’t search for the link name in the string of file paths correctly.