[AS][IDCS2] Relink to new graphic.

I have a script that partly works (which in many ways is more annoying than not working at all). The function of the script is to detect whether a link is an EPS and if there is an AI file with the same name located in the same folder as the EPS. If so, relink to AI. (My dept. is eventually moving to all AI files). Problem is, the relink function seems to be one step behind the “find EPS” so when to relinks the graphics it links it to what should have been the graphic once before. It’s very odd, in fact when I view the event log it all reads like it worked correctly, but the end result in the InDesign file is wrong.

I know one quirk I found in search for EPS is you can’t search for a file type, since InDesign technically reads the embedded PDF of the link.


tell application "Adobe InDesign CS2"
	tell active document
		repeat with p from 1 to count of every page
			set theLink to (every link whose file path contains ".eps")
			repeat with i from 1 to count of theLink
				set thePath to the file path of item i of theLink
				set AppleScript's text item delimiters to ".eps"
					if exists alias ((text item 1 of thePath) & ".ai") then
						relink link i to (text item 1 of thePath) & ".ai" as alias
					end if
				end try
			end repeat
		end repeat
	end tell
end tell



You might be best searching for the Link type instead of the file type.
open an indesign doc with an “.eps” in it and an ".ai"in it then run this:

tell application "Adobe InDesign CS2"
	tell document 1
		set t to (get link type of link 1)
		display dialog t as string
		set f to (get link type of link 2)
		display dialog f as string
	end tell
end tell

this may be a better road to go down, if i get chance i’ll look further into it!

Still having issues. I can’t search for links by file type because InDesign reads the embedded PDFs and not the vector-based AI format of the links. I can search for .EPS links easily enough via the link name or file path, but I still can’t get the relinking command to work propperly. Again it’s as if InDesign is one step behind and begins relink the wrong graphics. Thoughts??

I only have ID at work, so I can’t test my suspicion, but I see a potential glitch at “relink link i”; the current link of the document may not be the same as the current item in your list. Flying blind, I may be way off, so test this statement in your “if” block:

relink item i of thelink to (text item 1 of thePath) & ".ai" as alias

There also doesn’t appear to be any need for the nested repeat, as neither your p variable nor the pages are ever addressed. Kill.

THAT DID IT!!! I wish I knew why though. Proves I have a lot to learn still.