интересный вопрос.Я нашел отличный ответ, используя множество Applescript-ObjC от Applescript Guru Шейн Стэнли внешняя ссылка на MacScripter.net
Я немного попробовал и адаптировал (главным образомскопировал ...) его обработчик.Решение:
use scripting additions
use framework "Foundation"
use framework "AppKit"
property theRGBValues : missing value
-- check we are running in foreground
-- when starting from Script Editor, please use CTRL-CMD-R !
if not (current application's NSThread's isMainThread()) as boolean then
display alert "This script must be run from the main thread." buttons {"Cancel"} as critical
error number -128
end if
set my theRGBValues to missing value -- start off empty
-- get color panel
set thePicker to current application's NSColorPanel's sharedColorPanel()
current application's NSColorPanel's setPickerMode:(current application's NSWheelModeColorPanel)
-- get the action called by the eye-dropper button; hackish...
set theViews to thePicker's contentView()'s subviews()
repeat with aView in theViews
if aView's |class|() is current application's NSButton then
set theAction to aView's action()
exit repeat
end if
end repeat
-- set what happens when you click
thePicker's setTarget:me -- message will be sent to this script
thePicker's setAction:"colorPicked:" -- message will call handler of this name
-- show the panel
thePicker's orderFront:me
-- click the eye-dropper
aView's setState:(current application's NSOnState)
thePicker's performSelector:theAction
repeat -- loop until the user clicks
if theRGBValues is not missing value then exit repeat
delay 0.05
end repeat
set hexValue to (convertRGBColorToHexValue(theRGBValues))
set the clipboard to hexValue as text
(*****************************************
************* Handlers *********************
******************************************)
-- gets called when you click
on colorPicked:sender
-- get the color
set theColor to sender's |color|()
-- convert to correct colorspace
set newColor to theColor's colorUsingColorSpace:(current application's NSColorSpace's deviceRGBColorSpace())
-- get components
set theRed to newColor's redComponent()
set theBlue to newColor's blueComponent()
set theGreen to newColor's greenComponent()
-- close panel
sender's orderOut:me
-- set property
set my theRGBValues to {theRed * 255 as integer, theGreen * 255 as integer, theBlue * 255 as integer}
end colorPicked:
on convertRGBColorToHexValue(givenRGBValues)
set theHexList to {"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F"}
set theHexValue to ""
repeat with anRGBValue in givenRGBValues
set theFirstItem to item ((anRGBValue div 16) + 1) of theHexList
set theSecondItem to item (((anRGBValue / 16 mod 1) * 16) + 1) of theHexList
set theHexValue to (theHexValue & theFirstItem & theSecondItem) as string
end repeat
return ("#" & theHexValue) as string
end convertRGBColorToHexValue
Я изменил обработчик convertRGBColorToHexValue
для работы с данными, возвращаемыми палитрой цветов.
Получайте удовольствие!Майкл / Гамбург