Retrieve NSShadow values from RTF

(… or create RTF with shadow style)

I’m using a modified example from other posts / plyosoft.com

...
set plainTx to zAttrStrg's |string|()
set theLength to zAttrStrg's |length|()
set startIndex to 0
try
	repeat until (startIndex = theLength)
		set {zAttr, theRange} to zAttrStrg's attributesAtIndex:startIndex longestEffectiveRange:(reference) inRange:{startIndex, theLength - startIndex}
		set aText to (plainTx's substringWithRange:theRange) as string
		try
			set aShadow to (zAttr's valueForKeyPath:"NSShadow")
			if aShadow is not equal to missing value then
				log aShadow
				exit repeat
			end if
		end try
		set startIndex to current application's NSMaxRange(theRange)
	end repeat
end try

I do find a shadow like i.e.

(NSShadow {5.0999999999999996, -5.1500000000000004} blur = 5.05 color = {NSCalibratedRGBColorSpace 0 0 0 0.333333})

But I can’t find a way to retrieve the settings: offset (size), blur and color.

Found something in 10.3 notes:
An NSShadow may currently be used in one of two ways. First, it may be set, like a color or a font, in which case it is applied to all drawing until another shadow is applied or until the next graphics state restore. It may also be used as the value for the new NSShadowAttributeName text attribute, in which case it will be applied to the glyphs corresponding to the characters bearing this attribute. See the section on additional text attributes for the definition of NSShadowAttributeName.

But still no idea how to use that - even makes it more confusing.

As always, any help, hints, etc. are greatly appreciated.

Figured out.

...
set plainTx to zAttrStrg's |string|()
set theLength to zAttrStrg's |length|()
set startIndex to 0
try
	repeat until (startIndex = theLength)
		set {zAttr, theRange} to zAttrStrg's attributesAtIndex:startIndex longestEffectiveRange:(reference) inRange:{startIndex, theLength - startIndex}
		set aText to (plainTx's substringWithRange:theRange) as string
		try
			set aShadow to (zAttr's valueForKeyPath:"NSShadow")
			if aShadow is not equal to missing value then
				set shadowSize to aShadow's shadowOffset()
				log shadowSize
				set shadowBlur to aShadow's shadowBlurRadius()
				log shadowBlur
				set shadowClr to aShadow's shadowColor()
				log shadowClr
				if shadowClr is not equal to missing value then
					set aSpace to (shadowClr's colorSpace())
					
					set aRed to (shadowClr's redComponent())
					set aGreen to (shadowClr's greenComponent())
					set aBlue to (shadowClr's blueComponent())
					set aAlpha to (shadowClr's alphaComponent())
					
					set clrStrForFCP to (aRed as string) & " " & (aGreen as string) & " " & (aBlue as string) & " " & (aAlpha as string)
					log clrStrForFCP
				end if
				exit repeat
			end if
		on error errMsg
			log errMsg
		end try
		set startIndex to current application's NSMaxRange(theRange)
	end repeat
end try

Now I need to find out to create an attributed string with an shadow object :grin: