Tex-Edit Plus Styles

Howdy,
I need to insert a string of text into a Tex-Edit Plus document and the string
needs to contain different text styles. For instance, it needs to look like
this:
[b:000]Bold here [/b:000]Some plain text[b:000] More bold here[/b:000]
The bold parts will actually be HTML tags that need to stand out, but the
BBS wanted to eat the tags so this sample text will have to do. So, is
there a way to construct this and pass all of it to the TE+ document in
one slick motion?
I’ve tried to apply properties to variables but I’m getting no place fast.
Thanks for any tips that you might offer.
– Rob J

It’s not “one slick motion” but it does the job. Try playing around with it. Obviously make sure it has pasted correctly into your editor so that you have 3 lines of text before the fourth is added.
tell application “Tex-Edit Plus”
activate
make new window
tell window 1
set contents to “Hello, here I am
Bold here Some plain text More bold here
and some more plain text”
set insertion point before line 3 to “An added bold bit here” & return
set style of contents’s words 1 thru 2 of line 2 to bold
set style of contents’s words -3 thru -1 of line 2 to bold
set style of line 3 to bold
end tell
end tell

Hi,
I tried to make a search script to do this but I think there’s an easier way to write this. Just got Tex-Edit. Anyway, you could also replace the tags with bold after you have all the text written.
gl, Kel.

: The best way I know is to style the tags after they’re added to the text. Do
: I understand correctly that you want to style all the tags? If so you
: can do it like this:
: set theFile to (choose file with prompt
: “Select an HTML file:”)
: tell application “Tex-Edit Plus”
: open theFile
: tell window 1
: replace looking for “<^>" replacing with
: "^
” replacing with styles {style:{bold}}
: close saving yes
: end tell
: end tell
: Marc K. Myers < Marc@AppleScriptsToGo.com >
: AppleScriptsToGo
: 4020 W.220th St.
: Fairview Park, OH 44126
: (440) 331-1074
: [3/29/02 10:59:23 AM]

No, I only wanted to style a string which was being inserted into the
document. I finally hacked a solution together (find the newly inserted text
and then apply the style to the selection), but it caused the cursor to jump
to the selected text. The client decided that he would rather
do without the bold text. :wink:

Thanks anyway! I’ll add your suggestion to my repository for future reference.

Later,

Rob J

Ok. Figured it out.
<!doctype html public “-//w3c//dtd html 4.0 transitional//en”>
property tag_list : {“”, “”}
tell application “Tex-Edit Plus”
activate
tell front window
repeat with i in tag_list
replace contents looking for i replacing with i ¬
replacing with styles {style:{bold}}
end repeat
end tell
end tell
Later.

I finally settled on a search routine to find the target of boldness and then
apply the bold style to the result (it’s selected when found in a search).
tell application “Tex-Edit Plus”
search window 1 looking for “the text that I want to bold”
set style of selection to bold
end tell
Thanks to everyone for your input! :slight_smile:
– Rob J

: Howdy,

: I need to insert a string of text into a Tex-Edit Plus document and the
: string needs to contain different text styles. For instance, it needs to
: look like this: Bold here Some plain text More bold here

: The bold parts will actually be HTML tags that need to stand out, but the
: BBS wanted to eat the tags so this sample text will have to do. So, is
: there a way to construct this and pass all of it to the TE+ document in
: one slick motion?

: I’ve tried to apply properties to variables but I’m getting no place fast.

: Thanks for any tips that you might offer.

The best way I know is to style the tags after they’re added to the text. Do I understand correctly that you want to style all the tags? If so you can do it like this:

set theFile to (choose file with prompt "Select an HTML file:")
tell application "Tex-Edit Plus"
        open theFile
        tell window 1
                replace looking for "<^*>" replacing with "^*" replacing with styles {style:{bold}}
                close saving yes
        end tell
end tell

Marc K. Myers
Marc@AppleScriptsToGo.com
AppleScriptsToGo
4020 W.220th St.
Fairview Park, OH 44126
(440) 331-1074

[3/29/02 10:59:23 AM]

Hi Rob,
You’re not going to give up now? :slight_smile: This works:
<!doctype html public “-//w3c//dtd html 4.0 transitional//en”>
property the_list : {“”, “some text”, “”}
– Inserts the text from the_list with bold styles for the first and last items.
set {tag_1, mid_string, tag_2} to the_list
set the_string to the_list as string
tell application “Tex-Edit Plus”
activate
tell front window
set style of selection to plain
set selection to the_string
search contents looking for tag_2 finding previous ¬
with searching from cursor
set style of selection to bold
search contents looking for tag_1 finding previous ¬
with searching from cursor
set style of selection to bold
search contents looking for tag_2 finding next ¬
with searching from cursor
select insertion point after selection
end tell
end tell
The problem now is how can you make it so that the user can easily change the text to insert from the TE Script Menu.
Later, Kel.

Ok, you can do that by pressing Option when selecting the script in the menu.

: Hi Rob,
: You’re not going to give up now? :slight_smile: This works:
: property the_list : {“”, “some text”,
: “”} – Inserts the text from the_list with bold
: styles for the first and last items. set {tag_1, mid_string, tag_2} to
: the_list set the_string to the_list as string tell application
: “Tex-Edit Plus” activate tell front window
: set style of selection to plain set selection to the_string
: search contents looking for tag_2 finding previous ¬
: with searching from cursor set style of selection to
: bold search contents looking for tag_1 finding previous ¬
: with searching from cursor set style of selection to
: bold search contents looking for tag_2 finding next ¬
: with searching from cursor select insertion point
: after selection end tell end tell
: The problem now is how can you make it so that the user can easily change the
: text to insert from the TE Script Menu.
Hi Kel,
Yeah, your script would work fine (it’s similar to what I finally came up with).
The text which is inserted is generated by the script with no user input
required, so I wanted to insert it with style properties (to avoid search and
select), but this appears to be beyond the capabilities of TE+.
Thanks!
– Rob J