TexEdit Plus: One (?) scriptline won’t run on Intel machine?

Hi all,

I am installling my new MacPro and transferring all the scripts I used to work with for years. One of these scripts (also posted here in the scriptbuilders section) won’t run in my Intel machine. Not as an app, and not directly from script editor.
As far as I can see now it’s this line which gives an error (something with negative counting?). I commented out the rest of the script, so you can see what it’s about.
Normally char1 would give the position of this specific characters in a document, as a list. Which is necessary to find the beginning and ending of (for example) bold or italic text. Or in this case: ˜-’ (short line) where they shoud be ˜“’ (longer line).
But now… nothing.
The weird thing is, when I rewrite the line to:
set char1 to offset of (every character of paragraph 2)
It returns a list of character positions.

Anyone with Intel experiences to help me out a bit?

tell application "Tex-Edit Plus"
set numList to {"1", "2", "3", "4", "5", "6", "7", "8", "9", "0"}
	if exists window 1 then tell window 1
		set char1 to offset of (every character whose contents is "-")
	repeat with i from (count of items of char1) to 1 by -1
		set char2 to ((item i of char1 as integer) - 1)
		set char3 to ((item i of char1 as integer) + 1)
		set char4 to ((item i of char1 as integer) + 1)
		if (contents of character char2 is in numList and contents of character char3 is in numList) then
			set i to item i of char1
			set contents of character i to "“"
		end if
	end repeat
	end tell
end tell

Thanks Jacques,

But your script deletes the numbers placed around the ˜-'.

It is not only about replacing some characters. If you take a look at this script I did, I need to find the offset of characters so I can place a code before or after the first or last character of a styled text; like bold or italic.


I’ve just download Tex-Edit Plus to take a look. Kjeld’s dash-correcting script works on my G5, but is very slow. The following avoids the use of TEP’s ‘offset’ command and is much faster. It extracts the text from the document and looks for digit-dash-digit combinations in the result, rather than in the document itself. Hope it’s some help.

set numList to "1234567890"
tell application "Tex-Edit Plus"
	if (exists window 1) then tell window 1
		set txt to its text
		set astid to AppleScript's text item delimiters
		set AppleScript's text item delimiters to "-"
		set tiList to txt's text items
		set AppleScript's text item delimiters to astid
		set char to 0
		considering case
			repeat with i from 1 to (count tiList) - 1
				set ti1 to item i of tiList
				set ti2 to item (i + 1) of tiList
				set ti1Count to (count ti1)
				set char to char + 1 + ti1Count
				if (ti1Count > 0) and ((count ti2) > 0) and (character -1 of ti1 is in numList) and (character 1 of ti2 is in numList) then
					set character char to "“" -- ie. character char of front document.
				end if
			end repeat
		end considering
	end tell
end tell

Sure it is. Thanks, both of you for this input. I see some interesting new lines of codes passing by…

@ Jacques: When writing this script a few years ago, I always had troubles with code & style run & code when the style run was longer then 256 characters (then a bunch of text just disappeared). Seems this problem is either solved by using your suggestion or by updates of TexEdit:
tell (style run x whose style is theStyle) to set contents to theCode & it & endofStyle

@ Nigel: Never thought of using a list for searching the character position of something. Also interesting that it’s faster than searching for the offset in the document itself.

A first quick glance on it shows me new possibilities to rewrite the script this week, perhaps it solves my problem (I will check on Monday on my IntelMac at work). But still I am still curious to the answer of this one open question: why does this line not work on an Intel Mac? Do Intel Macs work different with Applescript?

tell application "Tex-Edit Plus"
	if exists window 1 then tell window 1
		set char1 to offset of (every character whose contents is "-")
	end tell
end tell

Well, I tried on the Intel mac today but still facing problems.
I have got this workaround for the styles, using wild cards, but this doesn’t work for superscript or subscript.

replace looking for "^*" looking for styles {style:{italic}, off styles:{bold, underline}} replacing with "<I>^*<I>"

@Jacques, did you run your script on an IntelMac?

Crucial lines like these

set T_count to count (style runs whose baseline ascent < 0)

are still returning a message like: ˜Procedure for object counting returned negative counting.’

Thanks Jacques,

I got things working again. If anyone is interested, you can download the final script in the scriptbuilders section.