Humph.
This won’t work in Tex-Edit:
if (character id -1 to character id -4) of paragraph p are TextToSearchFor then
Can anyone tell me the correct syntax? I can’t find it in the dictionary…
Humph.
This won’t work in Tex-Edit:
if (character id -1 to character id -4) of paragraph p are TextToSearchFor then
Can anyone tell me the correct syntax? I can’t find it in the dictionary…
Hi,
the reference is application > document > text > paragraph > character/text/word
tell application "TextEdit"
set t to text of document 1
if text -4 thru -1 of paragraph p of t is textToSearchFor then
-- do something
end if
end tell
Thanks StefanK.
That compiled, but it doesn’t seem to be returning JUST the last 4 characters of the paragraph.
Instead, it seems to be returning the entire paragraph.
I just “translated” your line. There is no return value. It’s an if condition
Yeah, but I stuck in
return text 1 thru 3 of paragraph p
just to check that I’m correctly asking for what I want, and I’m getting the whole para. in the result window.
this returns the first 3 characters of paragraph 3 of the current document,
if the last 4 characters are equal to textToSearchFor
set p to 3
tell application "TextEdit"
set t to text of document 1
if text -4 thru -1 of paragraph p of t is textToSearchFor then
return text 1 thru 3 of paragraph p of t
end if
end tell
Shoot, just realized.
Stefan, I’m using Tex-Edit, not TextEdit.
Sorry. I overlooked the missing “t”, in this case I’m not able to help
Thanks anyway.
This one seems to work for me.
The only real change is from text to characters, then forcing the list returned into a single string.
Here it is:
set p to 3
tell application "Tex-Edit Plus"
set t to text of document 1
if characters -4 thru -1 of paragraph p of t as string is textToSearchFor then
return characters -4 thru -1 of paragraph p of t as string
end if
end tell
Hope it helped,
SuperScripter
I’ve just had a look at a copy of Tex-Edit Plus I have on my other machine. There, Stefan’s script in post #6 works with the simple substitution of the application name. However, this is because the document text is returned as AppleScript text in the variable t, so the AppleScript reference ‘text -4 thru -1 of paragraph p of t’ works. If the reference is to the text inside the document, the range part has to be rephrased for Tex-Edit’s benefit:
set p to 3
tell application "Tex-Edit Plus"
tell text of document 1
if text from character -4 to character -1 of paragraph p is textToSearchFor then
return text from character 1 to character 3 of paragraph p
end if
end tell
end tell
Or, less fuss:
set p to 3
tell application "Tex-Edit Plus"
tell text of document 1
if paragraph p ends with textToSearchFor then
return text from character 1 to character 3 of paragraph p
end if
end tell
end tell