Rename/Relink imported pages indesign

I’ve made a script to relink importes pages to new indesign files.

The script works, I think, because by logging the items, I get the write answers.

Still I have a error: “–> error “‘file path’ is a read only property.” number 30474”

what am I doing wrong?


tell application "Adobe InDesign CS5"
	--choose path & doc
	set PathOrigArray to {"BE", "FR", "NL", "EX", "DE", "CZ"}
	set PathOrigID to choose from list PathOrigArray with prompt "Selecteer de map met originele bestanden." OK button name "Update book" without multiple selections allowed
	if PathOrigID is "false" then return
	
	
	set LinkOrigArray to {"BE.indd", "BL.indd", "FR.indd", "NL.indd", "EX.indd", "DE.indd", "CZ.indd"}
	set LinkOrigID to choose from list LinkOrigArray with prompt "Selecteer de suffix van de originele links." OK button name "Update book" without multiple selections allowed
	if LinkOrigID is "false" then return
	
	
	set PathNewArray to {"FR", "NL", "EX", "DE", "CZ"}
	set PathNewID to choose from list PathNewArray with prompt "Selecteer de map met nieuwe bestanden." OK button name "Update book" without multiple selections allowed
	if PathNewID is "false" then return
	
	set LinkNewArray to {"BE.indd", "BL.indd", "FR.indd", "NL.indd", "EX.indd", "DE.indd", "CZ.indd"}
	set LinkNewID to choose from list LinkNewArray with prompt "Selecteer de suffix van de nieuwe links." OK button name "Update book" without multiple selections allowed
	if LinkNewID is "false" then return
	
	set oldParam to check links at open of linking preferences
	set check links at open of linking preferences to false
	
	
end tell

tell application "Adobe InDesign CS5"
	activate document
	set listOfLinks to (every link of active document whose file path ends with "_" & LinkOrigID & "")
	repeat with m from 1 to count listOfLinks
		set thisLink to item m of listOfLinks
		try
			set ASTID to AppleScript's text item delimiters -- Store settings
			
			set TempPath to file path of thisLink as string
			set AppleScript's text item delimiters to ":" -- Everything splits at this character
			set TempPathBits to text items of TempPath
			
			repeat with i from 1 to count TempPathBits
				if (item i of TempPathBits) as string is equal to PathOrigID as string then
					set item i of TempPathBits to PathNewID
				end if
			end repeat
			
			set LinkPath to items 1 thru i of TempPathBits as string
			
			set AppleScript's text item delimiters to "_" -- Everything splits at this character
			
			set LinkPathBits to text items of LinkPath
			repeat with n from 1 to count LinkPathBits
				if (item n of LinkPathBits) as string is equal to LinkOrigID as string then
					set item n of LinkPathBits to LinkNewID
				end if
				
			end repeat
			
			set NewLinkPath to items 1 thru n of LinkPathBits as string -- set new path
			
			set file path of thisLink to NewLinkPath as string
		end try
	end repeat
	
	
end tell

Hi,

you used ‘relink’ in your description, but didn’t use it :wink:

relink‚v : Points the link to a new source file.
relink link
to any : The full path name of the new source file. Can accept: alias or string or string.

Thanks…

I reworked the script to apply it on my book. Some documents in my book doesn’t have files with the extension “.indd”, Now I get an error on those documents… (can’t get every link with “_EX.indd”)

I tried to insert one Try and End Try before setting usedGraphics, but it won’t work


tell application "Adobe InDesign CS5"
	--choose path & doc
	set PathOrigArray to {"BE", "FR", "NL", "EX", "DE", "CZ"}
	set PathOrigID to choose from list PathOrigArray with prompt "Selecteer de map met originele bestanden." OK button name "Update book" without multiple selections allowed
	if PathOrigID is "false" then return
	
	
	set LinkOrigArray to {"BE.indd", "BL.indd", "FR.indd", "NL.indd", "EX.indd", "DE.indd", "CZ.indd"}
	set LinkOrigID to choose from list LinkOrigArray with prompt "Selecteer de suffix van de originele links." OK button name "Update book" without multiple selections allowed
	if LinkOrigID is "false" then return
	
	
	set PathNewArray to {"FR", "NL", "EX", "DE", "CZ"}
	set PathNewID to choose from list PathNewArray with prompt "Selecteer de map met nieuwe bestanden." OK button name "Update book" without multiple selections allowed
	if PathNewID is "false" then return
	
	set LinkNewArray to {"BE.indd", "BL.indd", "FR.indd", "NL.indd", "EX.indd", "DE.indd", "CZ.indd"}
	set LinkNewID to choose from list LinkNewArray with prompt "Selecteer de suffix van de nieuwe links." OK button name "Update book" without multiple selections allowed
	if LinkNewID is "false" then return
	
	set oldParam to check links at open of linking preferences
	set check links at open of linking preferences to false
	
	
	activate
	if active book exists then
	else
		set GetParentPath to ((choose file with prompt "Kies een Indesignbook:" of type "IDb5.5"))
		open GetParentPath
		delay 1
	end if
end tell
tell application "Adobe InDesign CS5"
	tell active book
		set fileList to full name of book contents
	end tell
	
	repeat with aFile in fileList
		set theDoc to open aFile
		set myDocument to active document
		tell myDocument
			
			
				set usedGraphics to (every link of active document whose file path ends with "_" & LinkOrigID & "")
				
				repeat with m from 1 to count usedGraphics
					set currentGraphic to item m of usedGraphics
					
					try
						set ASTID to AppleScript's text item delimiters -- Store settings
						
						set TempPath to file path of currentGraphic as string
						set AppleScript's text item delimiters to ":" -- Everything splits at this character
						set TempPathBits to text items of TempPath
						
						repeat with i from 1 to count TempPathBits
							if (item i of TempPathBits) as string is equal to PathOrigID as string then
								set item i of TempPathBits to PathNewID
							end if
						end repeat
						
						set LinkPath to items 1 thru i of TempPathBits as string
						
						set AppleScript's text item delimiters to "_" -- Everything splits at this character
						
						set LinkPathBits to text items of LinkPath
						repeat with n from 1 to count LinkPathBits
							if (item n of LinkPathBits) as string is equal to LinkOrigID as string then
								set item n of LinkPathBits to LinkNewID
							end if
							
						end repeat
						
						set NewLinkPath to items 1 thru n of LinkPathBits as string -- set new path
						
						
						relink currentGraphic to file NewLinkPath
					
				end repeat
				close theDoc saving yes
			end try
		end tell
	end repeat
	display dialog "De documenten zijn aangepast"
	set check links at open of linking preferences to oldParam
	
end tell


Hi, Evisita. You’re getting the end of a file specification with file path, but you need a name. I’ve made a few suggestions”based on your original post”but I’m not certain of your intent and why some things are as they were; is there a reason for there being a disparity among your lists? I see that there are different item lengths and country order, and I wonder if they could be condensed.


set countryList to {"BE", "FR", "NL", "EX", "DE", "CZ"} --6 items with no BL... intentionally disparate?
set docSuffix to {"BE.indd", "BL.indd", "FR.indd", "NL.indd", "EX.indd", "DE.indd", "CZ.indd"} --7 items

set PathOrigID to choose from list countryList with prompt ¬
	"Selecteer de map met originele bestanden." OK button name "Update book" without multiple selections allowed
if PathOrigID is false then error number -128 --true/false are constants, not strings. This error is equivalent to "cancel"

set LinkOrigID to choose from list docSuffix with prompt ¬
	"Selecteer de suffix van de originele links." OK button name "Update book" without multiple selections allowed
if LinkOrigID is false then error number -128

set PathNewID to choose from list countryList with prompt ¬
	"Selecteer de map met nieuwe bestanden." OK button name "Update book" without multiple selections allowed
if PathNewID is false then error number -128

set LinkNewID to choose from list docSuffix with prompt ¬
	"Selecteer de suffix van de nieuwe links." OK button name "Update book" without multiple selections allowed
if LinkNewID is false then error number -128


tell application "Adobe InDesign CS5"
	set check links at open of linking preferences to false
	set listOfLinks to (document 1's links whose name ends with "_" & LinkOrigID)
	
	repeat with m from 1 to count listOfLinks
		set thisLink to item m of listOfLinks
		set TempPath to file path of thisLink as string
		set AppleScript's text item delimiters to ":"
		set TempPathBits to text items of TempPath
		
		repeat with i from 1 to count TempPathBits
			if (item i of TempPathBits) as string is equal to PathOrigID as string then
				set item i of TempPathBits to PathNewID
			end if
		end repeat
		
		set linkPath to items 1 thru i of TempPathBits as string
		set AppleScript's text item delimiters to "_" 
		set LinkPathBits to text items of linkPath
		
		repeat with n from 1 to count LinkPathBits
			if (item n of LinkPathBits) as string is equal to LinkOrigID as string then
				set item n of LinkPathBits to LinkNewID
			end if
		end repeat
		
		set NewLinkPath to items 1 thru n of LinkPathBits as string
		relink thisLink to NewLinkPath
	end repeat
end tell