• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: help needed getting 2nd last line of text
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: help needed getting 2nd last line of text


  • Subject: Re: help needed getting 2nd last line of text
  • From: Brian Christmas <email@hidden>
  • Date: Sun, 16 Dec 2012 18:41:53 +1100

Shane, thank you very, very much. I was part way to using the first method when your email arrived. It's plenty quick enough for my needs.

Regards

Santa


On 16/12/2012, at 2:58 PM, Shane Stanley <email@hidden> wrote:

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.

-- 
Shane Stanley <email@hidden>
'AppleScriptObjC Explored' <www.macosxautomation.com/applescript/apps/>
 

 _______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users

This email sent to email@hidden

References: 
 >help needed getting 2nd last line of text (From: Brian Christmas <email@hidden>)
 >Re: help needed getting 2nd last line of text (From: Shane Stanley <email@hidden>)
 >Re: help needed getting 2nd last line of text (From: Brian Christmas <email@hidden>)
 >Re: help needed getting 2nd last line of text (From: Shane Stanley <email@hidden>)
 >Re: help needed getting 2nd last line of text (From: Shane Stanley <email@hidden>)
 >Re: help needed getting 2nd last line of text (From: Shane Stanley <email@hidden>)

  • Prev by Date: Re: help needed getting 2nd last line of text
  • Next by Date: POSIX file behavior
  • Previous by thread: Re: help needed getting 2nd last line of text
  • Next by thread: POSIX file behavior
  • Index(es):
    • Date
    • Thread