Skip to main content
Inspiring
December 21, 2010
Question

Difficult (?) find and replace. AppleScript, ID CS4

  • December 21, 2010
  • 1 reply
  • 429 views

I have a catalog in which product descriptions are structured something like this:

Paragraph Style A

Paragraph Style B

Paragraph Style C

Paragraph Style D

but some products are like this:

Paragraph Style A

Paragraph Style B

Paragraph Style D

I want to insert a blank Paragraph Style C before Paragraph Style D for all products that are missing Paragraph Style C.

There are sometimes consecutive paragraphs with Style B, but there is never more than one paragraph with Style D, so the script has to look for the Style D paragraphs and then insert the Style C paragraph before that.

In addition I have to do some Find and Replace operations:

1) FInd the first instance of a period in every Paragraph Style A and replace with a tab

2) Find the first instance of an open parenthesis in every group of consecutive paragraphs of Style B and replace with a tab.

So, if a product description was like this:

Paragraph Style A

Paragraph Style B

Paragraph Style B

Paragraph Style B

Paragraph Style C

Paragraph Style D

the script would only find the first open parenthesis in the first Paragraph Style B and then move on to the next product.

I am using AppleScript, ID CS4

This topic has been closed for replies.

1 reply

Inspiring
December 23, 2010

Okay, part 1) was just a simple GREP find/change without any scripting required:

Find what: ^(.+?)\.

Change to: $1\t

Find Format: Paragraph Style A

(thanks to http://forums.adobe.com/message/2142915)

Any help on the rest?