• 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 09:10:38 +1100

Thanks Shane. Once more to the rescue!

As the text i wanted to remove could exists in multiple places in the Client list, I used the range to remove  and replace the 2nd last line, perfect.

Now, I need to identify and remove the 2nd to 9th lines in a variable list as well as the total count of lines/paragraphs.

I've tried

  set textStorage to textView's textStorage()
    -- append new text
    set newTextLength to textStorage's  |length|() as integer
    say 6
     set theRange  to textstorage's replaceOccurrencesOfString_withString_options_range_(linefeed,linefeed,0,{0,newTextLength-1})  #backwardsSearch
    say theRange

  

to try and get the count of linefeeds, but it doesn't work. Any ideas please anyone?

I need a rolling list of the last X client details (there's 8 lines of info for each client)

Regards

Santa




On 15/12/2012, at 9:50 PM, Shane Stanley <email@hidden> wrote:

On 15/12/2012, at 7:11 PM, Brian Christmas <email@hidden> wrote:

I need to remove and replace the second last line in the field if the mail processes ok, but cant work out how to do it. I can insert the appropriate text ok, but the removal has me stumped.

The line to remove is "If this remains visible, then this job did not process correctly."

To delete some text, you need to know its range. So the easiest way is probably to get the contents of the text view as an NSString, and ask it for the range of the target using, then delete that range:

set allText to textView's |string|() -- gets the full contents as an NSString
set theRange to allText's rangeOfString_("If this remains visible, then this job did not process correctly." & linefeed)
tell textStorage to deleteCharactersInRange_(theRange)

If you instead want to replace the text, use:

tell textStorage to replaceCharactersInRange_withString_(theRange, "Whatever" & linefeed)

 tell current application's NSColorList to set AppleColors to colorListNamed_("Apple")
 set someColor to AppleColors's colorWithKey_("Black")

For basic colors there are dedicated class methods, like this:

set someColor to current application's NSColor's blackColor()

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

  • Follow-Ups:
    • Re: help needed getting 2nd last line of text
      • From: Shane Stanley <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>)

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