Automatic text selection.....how?

Hi

I have this text in Word:

<!-------------START POINT-------------->

<!-------------END POINT-------------->

I have several thousands of this text block. Each text block begins with <!-------------START POINT-------------->

and ends with

What’s in between those 2 points is different text from block to block. But it always starts with the same sentences.
How can i tell word, “select everything from” <!-------------START POINT--------------> to <!-------------END POINT-------------->

That way i don’t have to always scroll from start to finish of each block.

Thanks

Zen

- Record Description

Is this even possible to script?
Please i really need help.

Thanks so much!

Hi,

try this


property startPoint : "<!-------------START POINT-------------->"
property endPoint : "<!-------------END POINT-------------->"

tell application "Microsoft Word"
	set theText to content of text object of active document
end tell
set startIndex to (offset of startPoint in theText) - 1
set endIndex to (offset of endPoint in theText) + (count endPoint) - 1

tell application "Microsoft Word"
	set myRange to create range active document start startIndex end endIndex
	select myRange
end tell


Thanks a lot Stefan.

Would it be possible that i use this script in Textedit?

no, TextEdit has no selection property and even with GUI scripting it’s not possible to set the selected text

Do you know another word processing app that can run that script but way faster than Word?
The script works well but it takes like 5 to 10 seconds each time to select the text.

Is Page or Textwrap faster. When i say fast i mean like Textedit. Even if you select long pages of text the app does not lag or there’s no delay when you copy paste. But i need an app that reads scripts.

Thanks for the script

try TextWrangler, it’s free and very well scriptable


property startPoint : "<!-------------START POINT-------------->"
property endPoint : "<!-------------END POINT-------------->"

tell application "TextWrangler"
	set theText to contents of text window 1
end tell
set startIndex to (offset of startPoint in theText)
set endIndex to (offset of endPoint in theText) + (count endPoint) - 1

tell application "TextWrangler"
	tell window 1 to select ( characters startIndex thru endIndex )
end tell


Or, to keep the code “in house”:


property startPoint : "<!-------------START POINT-------------->"
property endPoint : "<!-------------END POINT-------------->"

tell application "TextWrangler"
	tell contents of text window 1
		set {found object:{characterOffset:startIndex}} to (find startPoint)
		set {found object:{characterOffset:startIndex2, length:len}} to (find endPoint)
		set endIndex to startIndex2 + len - 1
		select (characters startIndex thru endIndex)
	end tell
end tell

This has the advantage that every time it’s run, it selects the next instance of the block in the text, eventually erroring when there are no more.

Edit: Or better still! :


property startPoint : "<!-------------START POINT-------------->"
property endPoint : "<!-------------END POINT-------------->"

tell application "TextWrangler"
	tell contents of text window 1
		find startPoint with selecting match
		find endPoint options {extend selection:true} with selecting match
	end tell
end tell

This doesn’t error when there are no more blocks. You have to check the ‘found’ property of each ‘find’ result.

This is great, Nigel, thanks.
I knew that TextWrangler’s scripting skills are very powerful,
but I just looked at the dictionary quickly for the select command

What a fun way to spend a Sunday morning! :slight_smile:


property blockPattern : "<!-------------START POINT-------------->[\\s\\S]*?<!-------------END POINT-------------->"

tell application "TextWrangler" to find blockPattern searching in text of document 1 options {search mode:grep} with selecting match

Hey guys thanks so much, your making my day! I’ll try this and give you news.

I can’t thank you enough

Have a wonderful day or night ; )

Zen

How to add the “cut” function to this script:

property startPoint : “<!-------------START POINT-------------->”
property endPoint : “<!-------------END POINT-------------->”

tell application “TextWrangler”
tell contents of text window 1
find startPoint with selecting match
find endPoint options {extend selection:true} with selecting match
end tell
end tell

Thanks

Zen