Applescript:选择颜色,颜色 return
Applescript: Choose color, color return
我想做的是:
set retry to true
repeat while retry is true
display dialog "In the next window you'll have to choose a color!" buttons {"Cancel", "COLORR!"} cancel button 1 default button 2
set Chosencolor1 to (choose color)
display dialog "The chosen color is: " & Chosencolor1 & " Is this right?" buttons {"NO", "YES"}
if the button returned of the result is "no" then
set retry to true
display dialog "Retry is now: " & retry
else
set retry to false
display dialog "Retry is now: " & retry
end if
end repeat
end
但是当我 运行 这段代码时,它会 return 一个数字颜色代码。但我想要的是它会 return 一个颜色名称,例如:淡蓝色、蓝色、绿色等
我知道的唯一方法是做类似的事情:
if the chosencolor1 is "000" then
set the chosencolor1 to "Black"
end if
end
还有其他更简单的方法吗?或者这是不可能的?
感谢阅读,
乔特
来自 AppleScript 语言指南 选择颜色:
Result The selected color, represented as a list of three integers
from 0 to 65535 corresponding to the red, green, and blue components
of a color; for example, {0, 65535, 0} represents green.
如您所料,获得文本响应的唯一方法是使用用户选择的列表值自行编程。
这里是一个非常简单的例子,它添加了所选 RGB 整数的所有值,并确定它是否更接近黑色或白色:
set myColor to choose color
display dialog ("You have chosen: " & my fetchColorName(myColor))
to fetchColorName(clst)
set totalColorValue to ((item 1 of clst) + (item 2 of clst) + (item 3 of clst))
set blackWhiteMidpoint to (196605 / 2)
if totalColorValue < blackWhiteMidpoint then
set colorName to "A color closer to black than white."
else
set colorName to "A color closer to white than black."
end if
return colorName
end fetchColorName
我想做的是:
set retry to true
repeat while retry is true
display dialog "In the next window you'll have to choose a color!" buttons {"Cancel", "COLORR!"} cancel button 1 default button 2
set Chosencolor1 to (choose color)
display dialog "The chosen color is: " & Chosencolor1 & " Is this right?" buttons {"NO", "YES"}
if the button returned of the result is "no" then
set retry to true
display dialog "Retry is now: " & retry
else
set retry to false
display dialog "Retry is now: " & retry
end if
end repeat
end
但是当我 运行 这段代码时,它会 return 一个数字颜色代码。但我想要的是它会 return 一个颜色名称,例如:淡蓝色、蓝色、绿色等
我知道的唯一方法是做类似的事情:
if the chosencolor1 is "000" then
set the chosencolor1 to "Black"
end if
end
还有其他更简单的方法吗?或者这是不可能的?
感谢阅读,
乔特
来自 AppleScript 语言指南 选择颜色:
Result The selected color, represented as a list of three integers from 0 to 65535 corresponding to the red, green, and blue components of a color; for example, {0, 65535, 0} represents green.
如您所料,获得文本响应的唯一方法是使用用户选择的列表值自行编程。
这里是一个非常简单的例子,它添加了所选 RGB 整数的所有值,并确定它是否更接近黑色或白色:
set myColor to choose color
display dialog ("You have chosen: " & my fetchColorName(myColor))
to fetchColorName(clst)
set totalColorValue to ((item 1 of clst) + (item 2 of clst) + (item 3 of clst))
set blackWhiteMidpoint to (196605 / 2)
if totalColorValue < blackWhiteMidpoint then
set colorName to "A color closer to black than white."
else
set colorName to "A color closer to white than black."
end if
return colorName
end fetchColorName