🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: adobe.scripting.indesign
Article #16033

Re: good AppleScript for multiple text find/replace?

#16033
From: Jay_Fraser
Date: Wed, 22 Oct 2003 22:21
50 lines
1915 bytes
Ted,

Try this:



tell application "InDesign 2.0.2" 
	set find preferences to nothing 
	set change preferences to nothing 
	set myDocument to active document 
	set myFindList to {"John", "Paul", "George", "Ringo"} 
	set myChangeList to {"Crosby", "Stills", "Nash", "Young"} 
	tell myDocument 
		if (count myFindList) is not equal to (count myChangeList) then 
			activate 
			display dialog "Lists do not match!" buttons {"cancel"} 
		end if 
		repeat with i from 1 to (count myFindList) 
			set myFindThis to item i of myFindList 
			set myChangeThis to item i of myChangeList 
			set myFoundItems to {}

			set myFoundItems to search myDocument with find attributes {find text:myFindThis, whole word:true}

			try 
				myFoundItems 
			on error 
				set myFoundItems to {} 
			end try

			if (count myFoundItems) > 0 then 
				repeat with j from (count myFoundItems) to 1 by -1 
					set myFoundItem to item j of myFoundItems 
					set contents of myFoundItem to myChangeThis 
				end repeat 
			end if

		end repeat 
	end tell 
end tell



I don't know what will happen w/ your "San Francisco" sample, as it is more than one word. You might have to ax the

whole word:true

bit. Let me know if this works for you.

Jay
Technical Details
Message-ID: <2ccdee4b.0@webx.la2eafNXanI>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!webx
References: <2ccdee4b.-1@webx.la2eafNXanI>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f939a,7a041aff3599544f
X-Google-Attributes: gidf939a,public
X-Google-ArrivalTime: 2003-10-22 15:37:53 PST
From: Jay_Fraser@adobeforums.com
Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!fu-berlin.de!newsfeed01.sul.t-online.de!t-online.de!webx
Newsgroups: adobe.scripting.indesign
Subject: Re: good AppleScript for multiple text find/replace?
Message-ID: <2ccdee4b.0@webx.la2eafNXanI>
Date: Wed, 22 Oct 2003 15:21:19 -0700
References: <2ccdee4b.-1@webx.la2eafNXanI>
Lines: 45
MIME-Version: 1.0
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit