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.
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
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.
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
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
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
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