Author Topic: Tex Edit Plus: another issue I keep having  (Read 2391 times)

0 Members and 1 Guest are viewing this topic.

Offline AutoFetishist

  • Sr. Member
  • ****
  • Posts: 397
  • Karma: 2
  • Gender: Male
Tex Edit Plus: another issue I keep having
« on: September 19, 2011, 11:36:01 AM »
Hi everyone, long time no conversation.

I have a handler go through a text file and change ALL CAPPED words to Title Cased Words.

I want this to occur selectively though: I want "Restricted Securities" to be converted when those two words comprise a heading, but
when the words are in a sentence, as in "There are many restricted securities that the fund invests in" I would not want the conversion applied.

Is there a way to restrict this? I don't know how one would direct the script to only change the phrase when the phrase comprises the entire paragraph.


Offline Publi-Script

  • Administrator
  • Hero Member
  • *****
  • Posts: 596
  • Karma: 16
  • Gender: Male
  • Automate your Life!
    • Publi-Script.com
Re: Tex Edit Plus: another issue I keep having
« Reply #1 on: September 19, 2011, 12:48:13 PM »
You have to go at this as a two steps approach.

tell application "Tex-Edit Plus"
   tell document 1
      replace looking for "^*" replacing with "^*" replacing with styles {color:black} -- making sure everuthing is black to start with
      replace looking for "restricted securities^c" replacing with "^*" replacing with styles {color:red} -- Making TARGET TEXT red
      change case (every word whose color is red) into sentence caps -- sentence case the TARGET TEXT
   end tell
end tell

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: Tex Edit Plus: another issue I keep having
« Reply #2 on: September 19, 2011, 01:04:25 PM »
Is the key the "^c" after the phrase?

Offline Publi-Script

  • Administrator
  • Hero Member
  • *****
  • Posts: 596
  • Karma: 16
  • Gender: Male
  • Automate your Life!
    • Publi-Script.com
Re: Tex Edit Plus: another issue I keep having
« Reply #3 on: September 19, 2011, 01:26:55 PM »
Actually, the "key" would be to encase your expression between "^c" meaning {paraMark}Your text{paraMark} thus ensuring that your text is indeed a paragraph (but your would also have to account for the possibility that your "target" heading starts the document in which case there won't be a preceding paraMark).

You could also go at it paragraph by paragraph which would be slower.

The real key here is to pre-qualify your text by changing its style and then apply your modifications on that style alone.

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: Tex Edit Plus: another issue I keep having
« Reply #4 on: September 19, 2011, 01:33:34 PM »
Great.

I'll try it later...

Offline AutoFetishist

  • Sr. Member
  • ****
  • Posts: 397
  • Karma: 2
  • Gender: Male
Re: Tex Edit Plus: another issue I keep having
« Reply #5 on: October 11, 2011, 10:27:00 AM »
Sorry, my earlier post must not have posted.

I guess where my problem comes in how I'm doing my searching, by looping through each paragraph, like so:


tell application "Tex-Edit Plus"
     tell document 1
         
          repeat with p from 1 to count of paragraph
               if (search paragraph p looking for "^*" looking for styles {style:{bold}, color:black}) then
                    replace paragraph p looking for "^*" looking for styles {style:{bold}, color:blue} replacing with "@00 Subhead1:" replacing with styles {style:{bold}, color:blue}
               end if
          end repeat
     end tell
end tell

Is there a way to have the Applescript search, in a paragraph, for "restricted securities^c" ?

That's what I don't know.

Offline Publi-Script

  • Administrator
  • Hero Member
  • *****
  • Posts: 596
  • Karma: 16
  • Gender: Male
  • Automate your Life!
    • Publi-Script.com
Re: Tex Edit Plus: another issue I keep having
« Reply #6 on: October 11, 2011, 11:06:58 AM »
Sorry, my earlier post must not have posted.

I guess where my problem comes in how I'm doing my searching, by looping through each paragraph, like so:


tell application "Tex-Edit Plus"
     tell document 1
         
          repeat with p from 1 to count of paragraph
               if (search paragraph p looking for "^*" looking for styles {style:{bold}, color:black}) then
                    replace paragraph p looking for "^*" looking for styles {style:{bold}, color:blue} replacing with "@00 Subhead1:" replacing with styles {style:{bold}, color:blue}
               end if
          end repeat
     end tell
end tell

Is there a way to have the Applescript search, in a paragraph, for "restricted securities^c" ?

That's what I don't know.

Actually your code is wrong... You are making a test on on set of values [looking for "^*" looking for styles {style:{bold}, color:black}] and then making a change on the same selection but with different properties [looking for "^*" looking for styles {style:{bold}, color:blue}]

Furthermore, you do not need to "pre-qualify" you replace command (unless you are in a possible infinite loop), the replace command will not throw an error is the search string is not found.

as for the last bit, replacing document 1 looking for "restricted securities^c" would indeed search all paragraphs.

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: Tex Edit Plus: another issue I keep having
« Reply #7 on: October 11, 2011, 02:07:17 PM »
You're right about the if statement, I was actually just cobbling together some different code snippets to demonstrate what I was trying to do.

I'll try your suggestion. Thanks for the explanation.