Applescript: Indesign Grep Find & Replace

Hi

I’m using the following line to set what my grep search should find.

set find what of find grep preferences to myFindGrep

However I also want to sconfin the search for to a paragraph style which can be seen in the ‘Find Format’ box of the panel. I can’t find the syntax to reference this “ can anyone help?

Thanks

LJ

Try:

set applied paragraph style of find grep preferences to styleName

Hi Shane

Great, as always

thanks

LJ

You should also include:

set find grep preferences to nothing
set change grep preferences to nothing

beforehand, to clear any existing values.

Hi Shane

Already got that one :slight_smile:

Here’s what I was working on.

I needed a script to export single page PDF’s that would be named from the content set with a paragraph style on each page of a multi-page PDF. e.g. business cards, would have the name set in a paragraph style called ‘name’ then when you run the script you would get a PDF file name like ‘Business cards-1-Shane.pdf’ & ‘Business cards-2- Dave.pdf’ etc.

All you have to do is change the myPDFPresetName to one of your own the files will be saved right next to your existing document. I also assume that you will only use the style once per page and keep it short!

Here’s the code.

tell application “Adobe InDesign CS6”
set myDocument to document 1
set MyFoundWordsList to {}
set find grep preferences to nothing
set change grep preferences to nothing


–get paragraph styles and let the user select
set myParaListAll to the name of every paragraph style of myDocument
– get rid of basic paras etc.
set myParaList to items 3 thru (count myParaListAll) of myParaListAll
–display dialog myParaList as string
set mySelectedParaStyle to (choose from list myParaList with title “Export Names from Styles.” with prompt “Select Your Paragraph Style.” without multiple selections allowed)
try

– Make a list of Names from the selected style
set myFindGrep to “.+”
–display dialog myFindGrep
set find what of find grep preferences to myFindGrep
set applied paragraph style of find grep preferences to mySelectedParaStyle as string

set MyFoundWords to find grep
–display dialog "MyFoundWords = " & (count MyFoundWords) giving up after 1

repeat with i from 1 to count MyFoundWords
set MyFoundWordsList to MyFoundWordsList & item i of MyFoundWords
end repeat

–display dialog MyFoundWordsList as string

display dialog “Exporting all your PDFs, I won’t be long.” giving up after 1

–display dialog item 1 of MyFoundWordsList

– Export PDFs
set theFilePath to file path of myDocument
set myDocName to text 1 thru -6 of (get name of document 1)
set myPDFPresetName to “FEN-SP“WC-HR”

repeat with i from 1 to count of MyFoundWordsList

tell PDF export preferences
set page range to (i as string)
end tell

tell active document
– export PDF
export format PDF type to theFilePath & (myDocName & “-” & i & “-” & item i of MyFoundWordsList & “-SP-HR.pdf”) as string using myPDFPresetName as string without showing options
end tell

	end repeat
	--
	--
	display dialog "All Done" giving up after 2
	--
end try

end tell