[INDCS2] Search/Relink to public folder

I’ve tried several variations of the below scripts. Nothing seems to work. I need to get every name of a link in an IDCS2 file and then determine if that link exists in a series of public folders shared on a server (my department’s icon library). I believe it’s a coercion problem since most errors have to do with “Can’t make X into type string [or text, or whatever else I tried]”. Thoughts, my attempts at this are below.


set oldDelims to AppleScript's text item delimiters
tell application "Finder"
	set TheFolder to choose folder
	set LinkList to every document file in every folder in TheFolder as string
	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 LinkList then
					set AppleScript's text item delimiters to ","
					set theNewPath to (text item of LinkList where exists name of item i of theLink)
					set NewLink to relink to theNewPath
					relink item i of theLink to (NewLink) as alias
				end if
			end repeat
		end tell
	end tell
end tell
set AppleScript's text item delimiters to oldDelims

I’m trying to separate the long string ofr doc and folders into text items so I can pinpoint a single filepath for the relinking.

Also, this was a simple test to see if I could find known text within the string from Finder. It’s a no-go as well.


tell application "Finder"
	set TheFolder to choose folder
	set theWord to {"Brain"}
	set LinkList to every document file in every folder in TheFolder
	if exists theWord in LinkList  then
		beep
	end if
end tell

Model: g5
AppleScript: Script Editor
Browser: Safari 419.3
Operating System: Mac OS X (10.4)

Hi

Try this to check whether a linked item is in a certain folder.

tell application "Adobe InDesign CS3"
	activate
	tell active document
		set theLink to name of every link
		repeat with i in theLink
			tell application "Finder"
				activate
				if (exists (file i) in folder (choose folder)) then
					display dialog "its there"
				else
					display dialog "it ain't there"
				end if
			end tell
		end repeat
	end tell
end tell

The problem that you are running into is that you are compaing the name of the link, which is the file name without the path, to a list of file paths. What you need to do is get a list of files names from the folder. Adding some complexity to your needs is that you are getting all the files from all the nested folders in the selected folder. A way to get around this is to have the Finder build 2 lists, one of the names and one of the paths of each file in the selected folder (and all its sub-folders). Then use the first list to compare the name of the link to and if it is there get it’s offset in the list and use that for the new path for the file. This seems to work for me, but if there are duplicate instances of a file then it will use the first one that it comes to:

set ExtensionList to {"bmp", "eps", "gif", "jpg", "pct", "pcx", "pdf", "png", "psd", "sct", "tif", "ai", "pdf"} --list of extensions that ID imports to eleminate any extra file types from the list.
set oldDelims to AppleScript's text item delimiters
set LinkNameList to {}
set LinkPathList to {}

tell application "Finder"
	set TheFolder to choose folder
	set LinkList to (every file of entire contents of TheFolder whose name extension is in ExtensionList)
	set AppleScript's text item delimiters to ":"
	repeat with i from 1 to count of LinkList
		copy name of item i of LinkList to end of LinkNameList
		copy (container of item i of LinkList) as string to end of LinkPathList
	end repeat
end tell
set AppleScript's text item delimiters to oldDelims
tell application "Adobe InDesign CS2"
	activate
	tell active document
		set theLink to every link
		repeat with i from 1 to count of LinkNameList
			if name of item i of theLink is in LinkNameList then
				set z to my getOffset(name of item i of theLink, LinkNameList)
				relink item i of theLink to (item z of LinkPathList & item z of LinkNameList) as alias
			end if
		end repeat
		update every link
	end tell
end tell

on getOffset(TheName, TheList)
	repeat with z from 1 to count of TheList
		if item z of TheList is TheName then return z
	end repeat
end getOffset