• 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: Requesting help with 'range' conversion, please
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Requesting help with 'range' conversion, please


  • Subject: Re: Requesting help with 'range' conversion, please
  • From: Brian Christmas <email@hidden>
  • Date: Tue, 02 Dec 2014 11:30:58 +1100

Shane, I’ve copied the piece of code from another app I have that works  under Mountain Lion, but it doesn’t compile under Yosemite. It sets…

tell current application's NSAttributedString to set theSameColoredAttributedText to theVariedAttributedText's mutableCopy()
So I assume I’m addressing the mutable copy.

 I’ve tried playing around with the line, and found…

tell theSameColoredAttributedText to setAttributes:(range {{attrsDict}, {location:(eachAttributedCharacterCounter - 1), |length|:1}})


compliles in Explorer 4, buit as the project won’t compile with Xcode 6, I don’t know if my change is correct.


Just tried something : seeing as ‘range’ wasn’t shown as red, I piped it, and success. Now I just have to try and work out why I’m getting an error 1 on my Xcode compile. Sorry for wasting your time, Shane.

tell theSameColoredAttributedText to setAttributes:attrsDict |range|:{location:(eachAttributedCharacterCounter - 1), |length|:1}


Regards

Santa


try
if weFoundAMatchingColorFlag then
#
# Make absolutely sure we're not out of range, mainly because we might 
# have removed the last linefeed from the text.
#
set p to 30
if (startOfTheMatchingText + allTheParagraphLengths) as integer > theTotal as integer then
set allTheParagraphLengths to (theTotal - startOfTheMatchingText) as integer
end if
set p to 31
#
# We've already offset the start of matching text by '-1' to allow for stored Attributed text being zero based.
#
tell current application's NSAttributedString to set theVariedAttributedText to alloc()'s initWithAttributedString:(mainMessagesAttributedText's attributedSubstringFromRange:{(startOfTheMatchingText) as integer, allTheParagraphLengths as integer})
set p to 32
#
# Now copy the Attributed paragraph text so we can set the copies text to a single color.
#
tell current application's NSAttributedString to set theSameColoredAttributedText to theVariedAttributedText's mutableCopy()
set p to 33
#
# Un-comment the following two lines if you want to check the
# text that's been grabbed and then copied.
#
# set tempStringText to "The grabbed string of Attributed text that has varied colors." & return & return & theVariedAttributedText's |string|() &return&return&return& "The copied string of Attributed text to set to same color." & return & return & theSameColoredAttributedText's |string|() as text
# display dialog tempStringText as text
#
end if
on error errmsg number errnum
set errorHasOccurred to true
my thereHasBeenAnError("Flash the message, method - 'Copy attributed text'", errmsg, errnum, 0, p)
end try
#
# ************◉  Now set copy of Attributed text to single color  ◉************
#
try
set p to 40
if weFoundAMatchingColorFlag then
set eachAttributedCharacterCounter to 0
set theFlashingNSColor to my matchAColor("Flashing Gold")
set p to 41
set fontAccess to current application's NSFontAttributeName
#
# Now, set every character of the copied text to a single color.
#
set tempStringText to theSameColoredAttributedText's |string|() as text
repeat with eachAttributedCharacterCounter from 1 to (count of tempStringText) # as integer
set p to 42
#
# Grab the Attributed font of each individual character
#
if item (eachAttributedCharacterCounter as integer) of tempStringText is not "" as text then
set p to 43
#
# Note that the Attributed text is zero based, so we subtract 1
#
set myFont to (theSameColoredAttributedText's attribute:(current application's NSFontAttributeName) atIndex:((eachAttributedCharacterCounter - 1) as integer) effectiveRange:{(eachAttributedCharacterCounter - 1) as integer, 1})
set p to 44
#
# Set the actual single character of the copied text to a single color,
# whilst keeping the font characteristics the same.
#
set attrsDict to (current application's NSDictionary's dictionaryWithObjects:{myFont, theFlashingNSColor} forKeys:{current application's NSFontAttributeName, current application's NSForegroundColorAttributeName})
set p to 45
tell theSameColoredAttributedText to setAttributes:(range {{attrsDict}, {location:(eachAttributedCharacterCounter - 1), |length|:1}})


end if
end repeat
end if
on error errmsg number errnum
set errorHasOccurred to true
my thereHasBeenAnError("Flash the message, method - 'Set attributed text copy to single color'", errmsg, errnum, eachAttributedCharacterCounter, p)
eachAttributedCharacterCounter
end try
On 2 Dec 2014, at 11:00 am, Shane Stanley <email@hidden> wrote:

On 2 Dec 2014, at 9:31 am, Brian Christmas <email@hidden> wrote:

tell theSameColoredAttributedText to setAttributes:attrsDict range:({location:(eachAttributedCharacterCounter - 1), |length|:1})

You're trying to call setAttrributes:range:, but on what?

-- 
Shane Stanley <email@hidden>
<www.macosxautomation.com/applescript/apps/>
Do not post admin requests to the list. They will be ignored. applescriptobjc-dev mailing list (email@hidden) Help/Unsubscribe/Update your Subscription: This email sent to email@hidden
References: 
 >Requesting help with 'range' conversion, please (From: Brian Christmas <email@hidden>)
 >Re: Requesting help with 'range' conversion, please (From: Shane Stanley <email@hidden>)
 >Re: Requesting help with 'range' conversion, please (From: Brian Christmas <email@hidden>)
 >Re: Requesting help with 'range' conversion, please (From: Shane Stanley <email@hidden>)

  • Prev by Date: Re: Requesting help with 'range' conversion, please
  • Next by Date: Re: Problem accessing secondary script
  • Previous by thread: Re: Requesting help with 'range' conversion, please
  • Next by thread: Re: Problem accessing secondary script
  • Index(es):
    • Date
    • Thread