Skip to main content
Participant
February 22, 2024
Question

Applescript GREP limit scope?

  • February 22, 2024
  • 2 replies
  • 214 views

Is there a way to tell GREP to limit its change scope to the current page? By default, it seems to change the entire document. I only want it to search and change the current page. I tried telling the current page to change grep but that generates an error. The current page does not know what change grep is.

 

set find what of find grep preferences to "stuff to find"

set change to of change grep preferences to "stuff to replace"

change grep

 

This topic has been closed for replies.

2 replies

rob day
Community Expert
Community Expert
February 22, 2024

Hi @grahams6813726 , As @brian_p_dts suggests you can set the grep prferences, get the active page and loop through the page’s text frames:

 

 

tell application id "com.adobe.indesign"
	set find grep preferences to nothing
	set change grep preferences to nothing
	set find change grep options to nothing
	
	set find what of find grep preferences to "World"
	set change to of change grep preferences to "There"
	
	--get the active page
	set ap to active page of active window
	
	tell active document
		set tf to every text frame of ap
		repeat with x in tf
			change grep of x
		end repeat
	end tell
end tell

 

 

brian_p_dts
Community Expert
Community Expert
February 22, 2024

You can get every text frame on a page and change grep on those. If you have anchored frames, you could iterate on all page items and change grep on found text frames. Don't know the AS way of writing that; I'm a JSX guy. But the page object has no change grep property as you've discovered.