Author Topic: restricting a search to ...  (Read 3420 times)

0 Members and 1 Guest are viewing this topic.

Offline AutoFetishist

  • Sr. Member
  • ****
  • Posts: 397
  • Karma: 2
  • Gender: Male
restricting a search to ...
« on: November 23, 2010, 09:44:08 AM »
a basic question,

I want to run search/replace routines in Tex Edit +
BUT I want to restrict the search to just bold occurrences.

How would I enable that, in the routine below?:

 repeat with ThisText in RunInWords
            set ThisText to ThisText as string
                    if paragraph p contains ThisText then
                         --if the occurrence of ThisText in para p is bold then
                         replace paragraph p looking for "^*" looking for styles {style:{bold}, color:blue} replacing with "@stylename:" replacing with styles {style:{bold}, color:green}
                    end if
                    --end if
end repeat
               
« Last Edit: November 23, 2010, 09:47:42 AM by AutoFetishist »

Offline Publi-Script

  • Administrator
  • Hero Member
  • *****
  • Posts: 596
  • Karma: 16
  • Gender: Male
  • Automate your Life!
    • Publi-Script.com
Re: restricting a search to ...
« Reply #1 on: November 23, 2010, 01:18:26 PM »
I believe your code is setup properly, however, you do not need the "if paragraph.." bit. Tex-Edit Plus is already "looking for" that text for you and won't do anything if it does not find it.

HTH
Michel Lemieux
Forum Administrator
-------------------------
OS X 10.6.4
Quark 6.5 / 7.5 / 8.1.6
Adobe Design Premium CS / CS2 / CS3 / CS4 / CS5
Script Debugger 4.5

Offline AutoFetishist

  • Sr. Member
  • ****
  • Posts: 397
  • Karma: 2
  • Gender: Male
Re: restricting a search to ...
« Reply #2 on: November 23, 2010, 01:24:00 PM »
Right, but I only want it to flag bold instances of the string.
Won't I need to narrow the searching somehow, to prevent it catching plain or italic instances of the string? 

Offline Publi-Script

  • Administrator
  • Hero Member
  • *****
  • Posts: 596
  • Karma: 16
  • Gender: Male
  • Automate your Life!
    • Publi-Script.com
Re: restricting a search to ...
« Reply #3 on: November 23, 2010, 01:37:35 PM »
Your current code will only look for the specified string on text that is  BOLD and BLUE and will replace it with your "@stylename:" set in BOLD and GREEN.

The key here is the "looking for styles" bit. That is what is narrowing your searches.

HTH
Michel Lemieux
Forum Administrator
-------------------------
OS X 10.6.4
Quark 6.5 / 7.5 / 8.1.6
Adobe Design Premium CS / CS2 / CS3 / CS4 / CS5
Script Debugger 4.5

Offline AutoFetishist

  • Sr. Member
  • ****
  • Posts: 397
  • Karma: 2
  • Gender: Male
Re: restricting a search to ...
« Reply #4 on: November 23, 2010, 01:59:58 PM »
Aha.
I see now. I wasn't explaining properly.

What I'm doing with this line: 
replace paragraph p looking for "^*" looking for styles {style:{bold}, color:blue} replacing with "@stylename:" replacing with styles {style:{bold}, color:green}

...is if one of my search strings is found, in bold, to then have the script apply a different QXP style sheet.

So if "dog" is one of my strings, the script would change:

   @stylesheet a: the dog is happy
to
   @stylesheet x: the dog is happy

So I need to first find the string (in bold), and that's what I don't know how to do.


Offline Publi-Script

  • Administrator
  • Hero Member
  • *****
  • Posts: 596
  • Karma: 16
  • Gender: Male
  • Automate your Life!
    • Publi-Script.com
Re: restricting a search to ...
« Reply #5 on: November 23, 2010, 02:06:39 PM »
Well currently your script is looking for EVERY TEXT set in BOLD and BLUE
What I think you want is:

replace paragraph p looking for ThisText looking for styles {Style:{bold}} replacing with ("@stylename:^*") replacing with styles {color:green}
Michel Lemieux
Forum Administrator
-------------------------
OS X 10.6.4
Quark 6.5 / 7.5 / 8.1.6
Adobe Design Premium CS / CS2 / CS3 / CS4 / CS5
Script Debugger 4.5

Offline AutoFetishist

  • Sr. Member
  • ****
  • Posts: 397
  • Karma: 2
  • Gender: Male
Re: restricting a search to ...
« Reply #6 on: November 23, 2010, 02:35:38 PM »
Why would it change every text?
I have my "change paragraph p" command nested inside an if block:


 repeat with ThisText in RunInWords
            set ThisText to ThisText as string
                    if paragraph p contains ThisText then
                         replace paragraph p looking for "^*" looking for styles {style:{bold}, color:blue} replacing with "@stylename:" replacing with styles {style:{bold}, color:green}
                    end if
end repeat
               
Wouldn't that ensure that the script will only do the replace within the parargraphs I want it to?
« Last Edit: November 23, 2010, 02:47:52 PM by AutoFetishist »

Offline Publi-Script

  • Administrator
  • Hero Member
  • *****
  • Posts: 596
  • Karma: 16
  • Gender: Male
  • Automate your Life!
    • Publi-Script.com
Re: restricting a search to ...
« Reply #7 on: November 23, 2010, 02:56:43 PM »
Sorry, I meant to say every text in paragraph p that is set in BOLD and BLUE. That is what the wilcard "^*" mean and why I suggested you use [looking for ThisText] instead
Michel Lemieux
Forum Administrator
-------------------------
OS X 10.6.4
Quark 6.5 / 7.5 / 8.1.6
Adobe Design Premium CS / CS2 / CS3 / CS4 / CS5
Script Debugger 4.5

Offline AutoFetishist

  • Sr. Member
  • ****
  • Posts: 397
  • Karma: 2
  • Gender: Male
Re: restricting a search to ...
« Reply #8 on: November 23, 2010, 03:15:41 PM »
Right, it changes anything in that that's bold & blue.
Which will be the stylesheet name.

I don't want to actually do anything to the occurences of ThisText.

I'm just using their presence to then decide to change the stylesheet.

Does that clarify what I'm attempting?


Offline Publi-Script

  • Administrator
  • Hero Member
  • *****
  • Posts: 596
  • Karma: 16
  • Gender: Male
  • Automate your Life!
    • Publi-Script.com
Re: restricting a search to ...
« Reply #9 on: November 23, 2010, 03:30:23 PM »
Yes it does...

Does your code do what you want it to do?
Michel Lemieux
Forum Administrator
-------------------------
OS X 10.6.4
Quark 6.5 / 7.5 / 8.1.6
Adobe Design Premium CS / CS2 / CS3 / CS4 / CS5
Script Debugger 4.5