On 16/12/2012, at 2:26 PM, Brian Christmas <
email@hidden> wrote:
When the total number of lines exceeds 80 * 8 (+1 line for a heading) then i need to remove lines 2 thru 9 of the displayed lines, (leaving the heading) until the number of displayed jobs drops to match the user displayed choice (80 in this case).
So what you need to know is the range of lines 2 thru 9, or the offset of lines 2 and 10. You could use standard AS: get the contents as a string, divide it into paragraphs, count the characters in each paragraph:
set theString to textView's |string|() as text
set thePars to paragraphs of theString
set allLocations to {0}
repeat with aPar in thePars
set end of allLocations to (item -1 of allLocations) + (length of aPar) + 1
if (count of allLocations) = 10 then exit repeat
end repeat
set theStart to item 2 of allLocations
set theEnd to item 10 of allLocations
set theRange to {theStart - 1, theEnd - theStart}
textStorage's deleteCharactersInRange_(theRange)
Or you could do it the ASObjC way:
set theString to textView's |string|()
set theLength to theString's |length|()
set searchLength to theLength
set searchStart to 0
set allLocations to {}
repeat 9 times
set {aLocation, aLength} to theString's rangeOfString_options_range_(linefeed, 0, {location:searchStart, |length|:searchLength}) as list -- find first instance
if aLength = 0 then exit repeat -- length of 0 means it wasn't found
set end of allLocations to aLocation
set searchStart to aLocation + 1 -- restrict search to after found instance
set searchLength to theLength - aLocation - 1
end repeat
set theStart to item 1 of allLocations
set theEnd to item 9 of allLocations
set theRange to {theStart, theEnd - theStart}
textStorage's deleteCharactersInRange_(theRange)
The first is probably a tad quicker, not that you'll notice.