Information Technology Reference
In-Depth Information
that there's already an app for sampling on-screen colors, available in the
UTILITIES folder of Applications—DigitalColor Meter, but it doesn't show CMYK
values.)
Creating a More Sophisticated App
A few extra lines of code can boost our new tool substantially and turn it into
a web developer's dream. The following AppleScript, when saved as an app
as described earlier, will write the color value chosen to the clipboard as a
hex value (that is, something like #6BACFF ). This can then be pasted into HTML
code, for example.
SET CHOSENCOLOR TO CHOOSE COLOR DEFAULT COLOR {65535, 65535, 65535}
SET THE FORMATTEDCOLOR TO MY HEX(CHOSENCOLOR)
ON HEX(CHOSENCOLOR)
SET THE HEX_LIST TO {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A",
"B", "C", "D", "E", "F"}
SET THE HEX_VALUE TO ""
REPEAT WITH I FROM 1 TO THE COUNT OF THE CHOSENCOLOR
SET THIS_VALUE TO (ITEM I OF THE CHOSENCOLOR) DIV 256
IF THIS_VALUE IS 256 THEN SET THIS_VALUE TO 255
SET X TO ITEM ((THIS_VALUE DIV 16) + 1) OF THE HEX_LIST
SET Y TO ITEM (((THIS_VALUE / 16 MOD 1) * 16) + 1) OF THE HEX_LIST
SET THE HEX_VALUE TO (THE HEX_VALUE & X & Y) AS STRING
END REPEAT
RETURN ("#" & THE HEX_VALUE)
END HEX
SET THE CLIPBOARD TO FORMATTEDCOLOR
Once you've typed the listing, click the Compile button to see whether it's
correct. Then save the script as an app, as described earlier, and it's ready
for use. Simply choose a color and click the OK button. The RGB hex value
will then be invisibly written to the clipboard, ready for pasting elsewhere.
Assigning a Custom Icon
There's one final tweak you can make to perfect your new app—assign it an
appropriate icon. To read how to change the icon of an app, see Tip 116,
Personalize Every Icon , on page 127 .
Also, you'll find an ideal image at /SYSTEM/LIBRARY/COLORPICKERS/NSCOLORPICKERWHEEL.COLOR-
PICKER/RESOURCES/NSCOLORWHEELIMAGE.TIFF . To open this file, start Preview, click File→
Open, make sure On My Mac is selected at the top left, and then hit
SHIFT + COMMAND + G . Then type the path shown earlier, and click Open to open
the file for viewing and converting into an icon, as described by the aforemen-
tioned tip.
 
 
 
 
 
Search WWH ::




Custom Search