Simple Relink Solution for CS2??

ALL I WANNA DO is

  • get all links of an indesign document where the file name starts with “4th” (1 thru 3 = “4th”)
  • change the text (1 thru 3) of the file names to “3rd”
  • ask indesign to “pretty please, with sugar” relink using the new file name “3rd”

INDESIGN CS2
MacOSX - 10.4.8

The file names are below:
4thgradeVocabAdvTEpgs_13.eps
3rdgradeVocabAdvTEpgs_13.eps

I have a few hundred of these, so after _99.eps I will be dealing with 3 digits instead of two.
Here the closest script I’ve found. There are several on this and other sites, but I just can’t seem to modify them to get what I need. I’ve also found one that will let you do this, but it does it One file at a time.
Any help at all will be appreciated.



--relinks files that end with _LR.tif with .tif
--version 1.0

set HRFolder to choose folder with prompt "Choose the High Res images folder"

set Mymissing to {return & return}

tell application "InDesign CS"
   tell document 1
       set theLinks to every link
       repeat with i from 1 to count of theLinks
           set thelink to item i of theLinks
           set theName to name of thelink as Unicode text
           if text -7 thru -1 of theName = "_LR.tif" then
               set theName to (text 1 thru -8 of theName) & ".tif"
           end if
           
           set newpath to (HRFolder as Unicode text) & theName
           try
               relink thelink to newpath
           on error
               copy (theName & return) to end of Mymissing
               
           end try
           update thelink
       end repeat
   end tell
   beep 2
   display dialog "Finished."
   if Mymissing is not {return & return} then
       display dialog "Cannot locate the High Res image: " & Mymissing
   end if
end tell

Model: MacOSX - 10.4.8
Browser: Firefox 2.0.0.2
Operating System: Mac OS X (10.4)

Hi
Not sure about the CS2 Links problem i don’t have indesign on this machine.
How ever you can replace text in the name of files with a finder script that comes with osx.
Look in your finder scripts or do a search for “Replace Text in Item names”

Hope this helps

A quick modification that should work:

set ArtFolder to choose folder with prompt "Third Grade art folder."

set Mymissing to {return & return}

tell application "Adobe InDesign CS2"
	tell document 1
		set theLinks to every link
		repeat with i from 1 to count of theLinks
			set thelink to item i of theLinks
			set theName to name of thelink as Unicode text
			if text 1 thru 3 of theName = "4th" then
				set theName to "3rd" & (text 4 thru -1 of theName)
			end if
			
			set newpath to (ArtFolder as Unicode text) & theName
			try
				relink thelink to newpath
			on error
				copy (theName & return) to end of Mymissing
				
			end try
			update thelink
		end repeat
	end tell
	beep 2
	display dialog "Finished."
	if Mymissing is not {return & return} then
		display dialog "Cannot locate the Third Grade image: " & Mymissing
	end if
end tell

Thanks guys! Worked great!

I did use the Finder script suggested to first rename the files and made a few edits.
I want to pass the user text returned from the “text to find” and “text to replace” dialogs down to the InDesign relink section.

This way I can use the script on many more occasions (and impress my boss), without editing the script each time. We use a 3rd grade versions of products as templates for 4th or 5th…etc.

I’m going to figure this out later… But I wanted to thank you for the help and let you know how it worked.

Here’s what I’ve got:

tell application "Finder" to set the source_folder to choose folder with prompt "Folder containing files to edit:"
--display dialog "Search and replace in:" buttons {"File Names", "Folder Names", "Both"} default button 3
--set the search_parameter to the button returned of the result

repeat
	display dialog "Enter text to find in the item names:" default answer "" buttons {"Cancel", "OK"} default button 2
	set the search_string to the text returned of the result
	if the search_string is not "" then exit repeat
end repeat

repeat
	display dialog "Enter replacement text:" default answer "" buttons {"Cancel", "OK"} default button 2
	set the replacement_string to the text returned of the result
	if the replacement_string contains ":" then
		beep
		display dialog "A file or folder name cannot contain a colon (:)." buttons {"Cancel", "OK"} default button 2
	else if the replacement_string contains "/" then
		beep
		display dialog "A file or folder name cannot contain a forward slash (/)." buttons {"Cancel", "OK"} default button 2
	else
		exit repeat
	end if
end repeat

display dialog "Replace "" & the search_string & "" with "" & the replacement_string & "" in every item name?" buttons {"Cancel", "OK"} default button 2

set the item_list to list folder source_folder without invisibles
set source_folder to source_folder as string
repeat with i from 1 to number of items in the item_list
	set this_item to item i of the item_list
	set this_item to (source_folder & this_item) as alias
	set this_info to info for this_item
	set the current_name to the name of this_info
	set change_flag to false
	if the current_name contains the search_string then
		set AppleScript's text item delimiters to the search_string
		set the text_item_list to every text item of the current_name
		set AppleScript's text item delimiters to the replacement_string
		set the new_item_name to the text_item_list as string
		set AppleScript's text item delimiters to ""
		my set_item_name(this_item, new_item_name)
	end if
end repeat

beep 2

on set_item_name(this_item, new_item_name)
	tell application "Finder"
		--activate
		set the parent_container_path to (the container of this_item) as text
		if not (exists item (the parent_container_path & new_item_name)) then
			try
				set the name of this_item to new_item_name
			on error the error_message number the error_number
				if the error_number is -59 then
					set the error_message to "This name contains improper characters, such as a colon (:)."
				else --the suggested name is too long
					set the error_message to error_message -- "The name is more than 31 characters long."
				end if
				--beep
				tell me to display dialog the error_message default answer new_item_name buttons {"Cancel", "Skip", "OK"} default button 3
				copy the result as list to {new_item_name, button_pressed}
				if the button_pressed is "Skip" then return 0
				my set_item_name(this_item, new_item_name)
			end try
		else --the name already exists
			--beep
			tell me to display dialog "This name is already taken, please rename." default answer new_item_name buttons {"Cancel", "Skip", "OK"} default button 3
			copy the result as list to {new_item_name, button_pressed}
			if the button_pressed is "Skip" then return 0
			my set_item_name(this_item, new_item_name)
		end if
	end tell
end set_item_name


set ArtFolder to source_folder as string
--choose folder with prompt "Choose the folder containing the new --links."

set Mymissing to {return & return}

tell application "Adobe InDesign CS2"
	tell document 1
		set theLinks to every link
		repeat with i from 1 to count of theLinks
			set thelink to item i of theLinks
			set theName to name of thelink as Unicode text
			if text 1 thru 3 of theName = "4th" then
				set theName to "3rd" & (text 4 thru -1 of theName)
			end if
			
			set newpath to (ArtFolder as Unicode text) & theName
			try
				relink thelink to newpath
			on error
				copy (theName & return) to end of Mymissing
				
			end try
			update thelink
		end repeat
	end tell
	beep 2
	display dialog "Finished."
	if Mymissing is not {return & return} then
		display dialog "Cannot locate the Third Grade image: " & Mymissing
	end if

end tell