"attribute runs" parsing

[size=150]Hi,

I need some examples of using “Attribute runs” as a way of geting at hilited style runs in a rtf doc within Devon. Thanks

andrew[/size]

Assuming that a rich text is visible in the frontmost window, then this script collects the highlighted strings:


tell application "DEVONthink Pro"
	set theHighlights to ""
	tell text of think window 1
		repeat with theAttribute in attribute runs
			if exists background of theAttribute then
				set theHighlights to theHighlights & (theAttribute as string) & return
			end if
		end repeat
	end tell
	display dialog theHighlights as string
end tell

Thanks alot Christian. I’ll see what I can do with this. I really appreciate how quickly and acurately you respond to all of these requests. It’s a testament to how great DT is. Thanks again.

Gabe

[size=150]

Hi, I tried your code and it doesnt work for me. Am using 1.1.1 and 10.3.9 for now. It fails at this line:


exists background of theAttribute

Any suggests how to get it work?? Thanks for example. :slight_smile: And if you can, how would I get the hililte color value as RGB too?

Andrew[/size]

Here’s an enhanced version compatible to 10.3.9 & 10.4.x and also checking that a specified background color is not white. This demonstrates also usage of RGB colors ranging from 0-65535:


tell application "DEVONthink Pro"
	set theHighlights to ""
	tell text of think window 1
		set skipped to false
		repeat with theAttribute in attribute runs
			set theProperties to properties of theAttribute
			set theBackground to background of theProperties
			if theBackground is not missing value and theBackground is not {65535, 65535, 65535} then
				set theHighlights to theHighlights & (theAttribute as string)
				if skipped then
					set theHighlights to theHighlights & return
					set skipped to false
				end if
			else
				set skipped to true
			end if
		end repeat
	end tell
	display dialog theHighlights as string
end tell

Oh yes! This works. :smiley:

here is my reworking:

tell application "DEVONthink Pro"
	set theHighlights to ""
	tell text of think window 1
		set skipped to false
		set C to 0
		repeat with theAttribute in attribute runs
			set theProperties to properties of theAttribute
			set theBackground to background of theProperties
			if theBackground is not missing value and theBackground is not {65535, 65535, 65535} then
				set C to C + 1
				set RGBvals to item 1 of theBackground & "," & item 2 of theBackground & "," & item 3 of theBackground
-- i would like a better way of getting the list, any suggestions??
				set theHighlights to theHighlights & ("quote:" & C & return & (RGBvals) & return & ((tab & tab & "\"" & theAttribute as string) & "\"") & return & return)
			else
				set skipped to true
			end if
		end repeat
	end tell
	set the clipboard to theHighlights as string
end tell

one more thing, can i see the code for next/prev nav to hilites, or tell me how i can do it, thanks. I want to jump to a color too.

DT Rocks! Never, never again will I have to hand transcribe quotes for my research projects. My fingers thank you. This is why a computer exists. :wink:

andrew

That’s not possible - the only (more or less useful) workaround is probably to use system events to script the Go > Previous/Next Highlight commands.