• 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: Hex colors in Tex-Edit X
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Hex colors in Tex-Edit X


  • Subject: Re: Hex colors in Tex-Edit X
  • From: JJ <email@hidden>
  • Date: Wed, 20 Nov 2002 14:45:28 +0200

> Gnarlodious wrote:
>
>>> Ah, I believe you need to add an OSAX (scripting addition) for that
>>> automatic
>>> conversion (HTML color to RGB list).
>> Not so! Here is the entire script which ran in OS 9:
>>
>> tell application "Tex-Edit"
>> activate
>> tell front window
>> set background color to black
>> repeat with n from 1 to count of style runs
>> if color of style run n is black then
>> set color of style run n to "#990099"
>> end if
>> end repeat
>> end tell
>> end tell
>
> Doesn't work for me. Perhaps you do have that coercion installed someplace?
> Pesky osaxen make it hard to tell where silent coercions are coming from
> sometimes. And you have to remove the guilty osax(en) and restart the
> system to get rid of them.


I've been investigating about this mysterious coercion, and I think this is
an Akua's one:

[[[[[[[[[[[[[[[
Class Million Color: A thirty two bit color (for coercing 3#FF00FF2 as
Million Color)
]]]]]]]]]]]]]]]

If you trash akua, the code doesn't work. Seems that coercions are destroyed
until restart, but commands will work anyway if you re-install akua.


> Anyway... it's possible to do this without the repeat loop:
>
> ======================================================================
>
> tell application "Tex-Edit"
> tell (every style run of text of window 1 whose color is black)
> if (count) is greater than 0 then set color to {39321, 0, 39321} --[1]
> end tell
> end tell
>
> ======================================================================
>
> This should be much faster.
>
> <wistful>Application scripting doesn't get any better than this.
>
> has
>
> [1] Not sure if that's the right RGB value for "#990099". Anyone know the
> correct formula for converting 8-bit colour to 16-bit? If I can find out,
> I'll post a library for doing HTML/RGB colour conversions.


Converting a 16-bit rgb color to web-hex-color is just as a 8-bit one, but
applying an extra base_256


# # # # # only partially tested # # # # #
set rgb_8bit to {153, 0, 153} -- or "990099" hex
RGB_8bit_TO_RGB_16bit(rgb_8bit)

on RGB_8bit_TO_RGB_16bit(rgb_8bit)
set rgb_16bit to {}
repeat with i in rgb_8bit
set plain_decimal to i * 256
set sum to plain_decimal div 256
set rgb_16bit to rgb_16bit & (plain_decimal + sum)
-- adjust plain decimal to base 256
end repeat
return rgb_16bit
end RGB_8bit_TO_RGB_16bit
# # # # # only partially tested # # # # #

And, directly:

"990099" --> {39321, 0, 39321}

# # # # # only partially tested # # # # #
property HexaChars : "0123456789ABCDEF"

set red_16bit to {65535, 0, 0}
set hex_red to Convert_16bitRGB_to_WebHex(red_16bit)

set red_hex to result
Convert_WebHex_to_16bitRGB(red_hex)

on Convert_16bitRGB_to_WebHex(thecolor)
set HTMLColor to {}
repeat with rgb in thecolor
set theresult to {}
set rgb to (((rgb as real) - 1) div 256)
repeat
set mod_Digit to (rgb) mod 16
set beginning of theresult to (contents of item (1 + mod_Digit)
of HexaChars)
set rgb to rgb div 16
if (rgb is 0) and ((count theresult) mod 2 = 0) then exit repeat
end repeat
set HTMLColor to HTMLColor & characters 1 thru 2 of (theresult as
text)
end repeat
HTMLColor as text
end Convert_16bitRGB_to_WebHex

on Convert_WebHex_to_16bitRGB(hexcolor)
set hexcolor to two_chunkize(hexcolor)
set converted to {}
repeat with z in hexcolor
set dec to 0
set z to reverse of (z's text items)
repeat with i from 1 to count z
try
set x to (offset of (z's item i) in HexaChars) - 1
on error
exit repeat
end try
set dec to dec + (x * (16 ^ (i - 1))) * 256
end repeat
set sum to dec div 256
set dec to dec + sum -- adjust plain decimal to base 256
set converted to converted & dec
end repeat
return converted
end Convert_WebHex_to_16bitRGB

on two_chunkize(hexcolor)
set chunkizado to {}
set i to 1
repeat
try
set chunkizado to chunkizado & (hexcolor's items i thru (i + 1)
as string)
on error
exit repeat
end try
set i to i + 2
end repeat
return chunkizado
end two_chunkize
# # # # # only partially tested # # # # #
Sign up for SBC Yahoo! Dial - First Month Free
http://sbc.yahoo.com
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: Basic AppleScript theory
  • Next by Date: Re: Autotype for OSX
  • Previous by thread: Re: Hex colors in Tex-Edit X
  • Next by thread: Re: Hex colors in Tex-Edit X
  • Index(es):
    • Date
    • Thread