jortpepe jortpepe - 4 months ago 21
AppleScript Question

Applescript color code from choose color

set colorcode to (choose color)
set password1 to text returned of (display dialog "Write the colorcode " & colorcode & " down below" default answer "" buttons {"continue", "cancel"} default button 1 cancel button 2)
if colorcode is password1 then
display dialog "correct" buttons {"1", "2"}
else
display dialog "false" buttons {"1", "2"}
end if
end


So well as u can probably see I tried to set 'colorcode' to the color code that returned of the 'choose color' and then u had to enter the correct color code of the color u picked and if u did that all correctly it would go to the correct dialog or otherwise it would go to the false dialog but it's not really working xD. As you can see Im not English so excuse me for any grammer mistakes.
Already thanks in advance, Jort.

Answer

First: The choose color handler returns a list of three integer values from 0 to 65535. The three list items stand for the red-, green- and blue-values.

Second: The text returnedfrom display dialog is of kind string.

You need to coerce the list to a string to compare it with the text returned:

set colorcode to (choose color)
set password1 to text returned of (display dialog "Write the colorcode " & colorcode & " down below" default answer "" buttons {"continue", "cancel"} default button 1 cancel button 2)
if (colorcode as text) is password1 then
    display dialog "correct" buttons {"1", "2"}
else
    display dialog "false" buttons {"1", "2"}
end if

Have a nice day! Michael / Hamburg

Comments