Author Topic: Can't change TI delimiters  (Read 4139 times)

0 Members and 1 Guest are viewing this topic.

Offline AutoFetishist

  • Sr. Member
  • ****
  • Posts: 397
  • Karma: 2
  • Gender: Male
Can't change TI delimiters
« on: March 29, 2011, 09:58:18 AM »
Can anyone see why I can't get Tex Edit to recognize tabs as my delimiter, in this code:



tell application "Tex-Edit Plus"
     set AppleScript's text item delimiters to tab
     tell window 1
          tell paragraph 1
               set style of (text from word -2 to word -1) to plain
          end tell
     end tell
     set AppleScript's text item delimiters to ""
end tell

when I run it, TE+ still seems to think commas are the delimiter.
Is there a trick that I don't know to switch?

Offline Publi-Script

  • Administrator
  • Hero Member
  • *****
  • Posts: 596
  • Karma: 16
  • Gender: Male
  • Automate your Life!
    • Publi-Script.com
Re: Can't change TI delimiters
« Reply #1 on: March 29, 2011, 12:23:30 PM »
Hi,

I believe you are mixing two different terminologies.

Text Item Delimiters is an Applescript concept to work with STRINGS by giving you the ability to separate them in text item. By default, TID are set to "" (empty string) meaning that any single character IS a text item.

Later on in your code you introduce the Paragraph and Word concept which is not the same thing. A WORD is not a TEXT ITEM. When you ask TE+ to target a WORD, it goes internally to see if it has a definition for WORD, if not, it goes back up one level until it finds a suitable definition for it.

In short, specifying a different TIDs did nothing to your code because nowhere do you make use of them (other than setting them).

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 Jean-Marie Schwartz

  • Sr. Member
  • ****
  • Posts: 436
  • Karma: 6
  • Gender: Male
Re: Can't change TI delimiters
« Reply #2 on: March 30, 2011, 02:17:40 AM »
Hi Michel! It's funny: reading your answer I went like "it's so obvious! how could AutoFetishist missed that?" Then having a look at his code I realised it's the kind of mistake I do all the time and I had never really know why it wouldn't work  :-\ Now I think it's clearer to me! Thanks for the input!
Jean-Marie Schwartz
May the Schwartz be with you :-)

= Mac Pro Quad-Core Intel 2.8 GHz 10 Go 1066 MHz DDR3 Mac OS 10.8.5 QuarkXPress 9.5.4.1 Adobe CS5 =

Offline AutoFetishist

  • Sr. Member
  • ****
  • Posts: 397
  • Karma: 2
  • Gender: Male
Re: Can't change TI delimiters
« Reply #3 on: March 30, 2011, 08:22:34 AM »
And yet...

in order to get TE to target the last word (or last 2 words) of this paragraph:
         The total amount was 100,000. 

tell application "Tex-Edit Plus"
     tell window 1
          tell paragraph 1
               set style of (words -2 through -1) to plain
          end tell
     end tell
end tell


Instead of the last 2 words, TE seems to be targeting the last 2 comma separated text items.
So it seems like I need to instruct TE+ to change however it defines words.

No?

Offline Publi-Script

  • Administrator
  • Hero Member
  • *****
  • Posts: 596
  • Karma: 16
  • Gender: Male
  • Automate your Life!
    • Publi-Script.com
Re: Can't change TI delimiters
« Reply #4 on: March 30, 2011, 09:10:12 AM »
Let me get this straight:

Your paragraph is "The total amount was 100,000."

then the last 2 words (as TE+ sees it) would be 100 and 000
In TE+ commas, periods and spaces CANNOT be part of a word nor can you change this behavior (as you can in Quark for instance)

my advise on this would be to determine OUTSIDE of TE+ what CHARACTERS need to be changed.

Here's how:
Quote
001   tell application "Tex-Edit Plus"
002      tell document 1
003         set paraText to (text of paragraph 1) as text
     
004         set oldDelims to AppleScript's text item delimiters
005         set AppleScript's text item delimiters to {space}
006         set paraWords to every text item of paraText
007         set AppleScript's text item delimiters to oldDelims
     
008         set myWord to (item -1 of paraWords) as text
009         set theOffset to my get_Offset(myWord, paraText)
010         set style of (characters theOffset through (theOffset + (myWord's length))) to plain
011      end tell
012   end tell


013   on get_Offset(thisWord, thisString)
014      return offset of thisWord in thisString
015   end get_Offset
Note:
The line numbers included with this script are there to aid future discussions. In order to use this script, you will have to strip all of them.


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: Can't change TI delimiters
« Reply #5 on: March 30, 2011, 11:45:53 AM »
"nor can you change this behavior"

sigh.

OK, so it must be done by Applescript analyzing the paragraph's text "outside" of TE+.


Offline AutoFetishist

  • Sr. Member
  • ****
  • Posts: 397
  • Karma: 2
  • Gender: Male
Re: Can't change TI delimiters
« Reply #6 on: April 19, 2011, 10:26:52 AM »
Michel,

How would I, in line 03
 
     set paraText to (text of paragraph 1) as text

have paraText just be the black text of paragraph 1?

Offline Publi-Script

  • Administrator
  • Hero Member
  • *****
  • Posts: 596
  • Karma: 16
  • Gender: Male
  • Automate your Life!
    • Publi-Script.com
Re: Can't change TI delimiters
« Reply #7 on: April 19, 2011, 05:59:53 PM »
Try this,

Quote
001   tell application "Tex-Edit Plus"
002      tell document 1
003         set originalBlackTexts to every style run of paragraph 1 whose color is black
004         set modifiedBlackTexts to {}
005         repeat with thisText in originalBlackTexts
006            set end of modifiedBlackTexts to my modifyText(thisText)
007         end repeat
     
008         repeat with i from 1 to originalBlackTexts's length
009            search paragraph 1 looking for "^*" looking for styles {color:black}
010            replace selection looking for "^*" replacing with (item i of modifiedBlackTexts) as text replacing with styles {color:white}
011         end repeat
012         replace paragraph 1 looking for "^*" looking for styles {color:white} replacing with "^*" replacing with styles {color:black}
013      end tell
014   end tell

015   on modifyText(textToModify)
016      set modifiedText to "test" -- for testing purposes only
017      -- your code here
018      return modifiedText
019   end modifyText
Note:
The line numbers included with this script are there to aid future discussions. In order to use this script, you will have to strip all of them.


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: Can't change TI delimiters
« Reply #8 on: April 21, 2011, 11:13:32 AM »
AAAAGGgH. But thank you.

One must do all of that, just to single out black text?

I guess I'm surprised. (Once again) It seems like specifying a portion of a paragraph shouldn't be so much more complicated.

Is there really no simpler code that will, in line 3,
      set paraText to (text of paragraph 1) as text

instead set paraText to be just the black text of paragraph 1?

Offline Publi-Script

  • Administrator
  • Hero Member
  • *****
  • Posts: 596
  • Karma: 16
  • Gender: Male
  • Automate your Life!
    • Publi-Script.com
Re: Can't change TI delimiters
« Reply #9 on: April 21, 2011, 12:39:05 PM »
AAAAGGgH. But thank you.

One must do all of that, just to single out black text?

I guess I'm surprised. (Once again) It seems like specifying a portion of a paragraph shouldn't be so much more complicated.

Is there really no simpler code that will, in line 3,
      set paraText to (text of paragraph 1) as text

instead set paraText to be just the black text of paragraph 1?


Well, I had to go with what I thought you were after... The problem here is that there is a possibility (from my POV) of black text appearing in multiple places within the same paragraph:

Quote
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec non ipsum nisi, at vulputate est. Mauris id mauris enim, quis hendrerit magna.

I doubt very much that you wish for those text regions to handled as one single occurrence so I wrote my code with that in mind.

Perhaps if you were to share the whole scenario, I could maybe offer a different avenue.

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