Page 1 of 1

How to select text without color?

Posted: 2012-02-25 03:47:34
by js
From a text with some parts marked with a color attribute, how can I select the rest, without a color attribute. (How can I select black text?)

Re: How to select text without color?

Posted: 2012-02-25 04:38:39
by Hamid
If the colour attribute is the same and not a part of a defined style, select all the text with that colour attribute (from the Statusbar color tag).
Then from the Edit menu apply Select:Inverse Selection.

Re: How to select text without color?

Posted: 2012-02-25 06:01:08
by js
Yes. But if there are many colors and let's say you don't want to find out how many and which ones. If all you want is "black" text. How about that?

Re: How to select text without color?

Posted: 2012-02-25 06:21:30
by Hamid

Re: How to select text without color?

Posted: 2012-02-25 12:11:30
by js
It looks indeed as if the commands necessaryfor doing a macro capable of selecting black text are being used in this other macro by Kino. Thank you.

Re: How to select text without color?

Posted: 2012-12-21 21:50:10
by Þorvarður
Hamid wrote:Try Kino's Select by Color macro:
http://www.nisus.com/forum/viewtopic.php?f=18&t=4151
Here is another much better macro by Kino that does exactly what the OP asked for. I'm not sure whether it belongs to the macros that originally come with NWP. I hope it is not redundant. Therefore I post it here. It's called "SelectSameOrOtherColor".


### Select Same or Different Color ###

# Select all text portions having or not having the same color as that of the insertion point.

# If the insertion point is at the very end of a text object, the macro uses Typing Attributes, which may not coincide with what the user expects.

Require Pro Version 1.2
$doc = Document.active
$sel = TextSelection.active
if $sel == undefined
exit
elsif $sel.location == $sel.text.length
$attr = $sel.displayTypingAttributes
else
$attr = $sel.text.displayAttributesAtIndex $sel.location
end
$activeColor = $attr.textColor
$sameColor = $otherColors = Array.new

foreach $text in $doc.allTexts
if $text.length
$i = 0
while $i < $text.length
$attr = $text.displayAttributesAtIndex $i
$range = $text.rangeOfDisplayAttributesAtIndex $i
$sel = TextSelection.new $text, $range
if $attr.textColor == $activeColor
$sameColor.appendValue $sel
else
$otherColors.appendValue $sel
end
$i = $range.bound
end
end
end

$same = 'Same Color'
$other = 'Other Colors'
$color = Prompt 'Select text portions in...', '', $same, $other
if $color == $same
$doc.setSelections $sameColor
else
$doc.setSelections $otherColors
end

### end of macro ###