Publi-Script Forums

Applescript / Javascript => Scripting in general => Topic started by: AutoFetishist on September 19, 2011, 11:36:01 AM

Title: Tex Edit Plus: another issue I keep having
Post by: AutoFetishist 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.

Title: Re: Tex Edit Plus: another issue I keep having
Post by: Publi-Script 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
Title: Re: Tex Edit Plus: another issue I keep having
Post by: AutoFetishist on September 19, 2011, 01:04:25 PM
Is the key the "^c" after the phrase?
Title: Re: Tex Edit Plus: another issue I keep having
Post by: Publi-Script 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
Title: Re: Tex Edit Plus: another issue I keep having
Post by: AutoFetishist on September 19, 2011, 01:33:34 PM
Great.

I'll try it later...
Title: Re: Tex Edit Plus: another issue I keep having
Post by: AutoFetishist 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.
Title: Re: Tex Edit Plus: another issue I keep having
Post by: Publi-Script 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
Title: Re: Tex Edit Plus: another issue I keep having
Post by: AutoFetishist 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.