Hi,
I have a doc with 300 pages where some words were colored on one color (RGB = 44, 91, 138) and I want to change them to (RGB = 25, 51, 77). How do I do that? How do I find and replace words with a particular color?
At that time I was starting to learn Pages and instead of creating a character style for the words I simply assigned the color to them…
I am trying to use this, but it is not working
tell application "Pages"
activate
tell document 1
tell body text
set numberWords to word count
display dialog numberWords
set allWords to every word whose color of first character is equal to {44, 91, 138}
repeat with oneWord in allWords
set text color of oneWord to {25, 51, 77}
end repeat
--display dialog palavras as string
end tell
end tell
end tell
allWords is giving me a blank list on a document that contains words in that color.
thanks in advance.
This one’s been annoying me for a few days. It turns out that the RGB slider values have to be multiplied by 257 to get the numbers used internally.
tell application "Pages"
activate
tell document 1
tell body text
set color of every word whose color of first character is {44 * 257, 91 * 257, 128 * 257} to {25 * 257, 51 * 257, 77 * 257}
end tell
end tell
end tell
It wouldn’t have helped even with the right numbers, as getting every word of a certain colour just returns the words, not references to their locations in the text.
WOW!!! Thank you so much… I was banging my head on the wall for days!!!
Why Apple does this kind of stuff? Why RGB is not 0-255?
you are
A W E S O M E!!!
thanks.
It does seem a bit strange, the way it’s done. The range 0-255 is the range of numbers that can be represented by a single byte. If you multiply one of these numbers by 257, you get a 2-byte value in which both bytes are exactly the same as the original:
set |single-byte value| to 44
tell |single-byte value| * 257 to return {|2-byte value|:it, |high byte|:it div 256, |low byte|:it mod 256}
--> {|2-byte value|:11308, |high byte|:44, |low byte|:44}
It’s like multiplying a single-digit number by 11: eg. 9 * 11 = 99
There may be some logic to this which is obvious to people who work with colours, or it could simply be that the 2-byte value looks exactly the same to both PPC and Intel processors.