Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > Applescript list dialogs

Applescript list dialogs
Thread Tools
Dedicated MacNNer
Join Date: Feb 2001
Location: Huddersfield, UK
Status: Offline
Reply With Quote
Jun 9, 2001, 10:23 AM
 
I posted this in the general developers forum a couple of days ago, but haven't got any resposes yet and as this forum now officially includes Applescript then here goes:

To 'introduce' myself to the Applescript language, I am writing a script that will create a web page based on answers to questions asked by the script.

In setting the background color, I would like the user to be able to select a color from a list presented to them.

<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier><font color = green>if</font> the button_pressed is <font color = red>"Colour picker"</font> then choose from list {<font color = red>"Red"</font>, <font color = red>"Green"</font>, <font color = red>"Blue"</font>, <font color = red>"Orange"</font>, <font color = red>"Yellow"</font>}
with prompt <font color = red>"Choose a colour:"</font> <font color = green>default</font> items {<font color = red>"Red"</font>}</font>[/code]

As shown above, displaying the list of color options is not a problem. However, once the user clicks on 'OK', they will be returned to a dialog box, defined by the following:

<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>display dialog <font color = red>"Enter a background colour (as a hexadecimal value):"</font>
<font color = green>default</font> answer <font color = red>"FFFFFF"</font> buttons {<font color = red>"Cancel"</font>, <font color = red>"Colour picker"</font>, <font color = red>"OK"</font>}</font>[/code]

My problem is copying the answer selected in the list into this dialog box so that the user can see that their choice has been recognised. A further problem is converting the items in the list into hexadecimal RGB values to display in the dialog box.

For example, in the first dialogue box, the user will be asked to enter a color value or pick from a list. Once the user has selected a colour from the list, I would like the script to display the color's equivalent hexadecimal RGB value in the original dialogue box. My questions are:

* How do I place the value returned from a list (the "choose from list" command) into another dialogue box?
* If the values displayed in the list are normal words, how do I get them to display their hexadecimal RGB values in the dialog box?

Thanks in advance for your help!
PM G4 DP 500 MHz, 768 Mb, DVD-ROM, 85 Gb, Mac OS X 10.3.9
PB G4 1.25 GHz, 512 Mb, DVD-R, 80 Gb, Mac OS X 10.4
     
Junior Member
Join Date: Apr 2001
Status: Offline
Reply With Quote
Jun 10, 2001, 09:42 PM
 
i guess i'm not really sure exactly what you're looking for, but hopefully this scriptlet will give some ideas:<BLOCKQUOTE><font size="1"face="Geneva, Verdana, Arial">code:</font><HR><pre><font size=1 face=courier>property color_text : {<font color = red>"Red"</font>, <font color = red>"Green"</font>, <font color = red>"Blue"</font>, <font color = red>"Orange"</font>, <font color = red>"Yellow"</font>}
property hex_Colors : {<font color = red>"FF0000"</font>, <font color = red>"<font color = blue>009900</font>"</font>, <font color = red>"<font color = blue>333399</font>"</font>, <font color = red>"FF6600"</font>, <font color = red>"FFFF00"</font>}

<font color = green>if</font> the button returned of (display dialog <font color = red>"Choose a color..."</font> buttons {<font color = red>"Cancel"</font>, <font color = red>"Colour picker"</font>} <font color = green>default</font> button <font color = red>"Colour picker"</font>) = <font color = red>"Colour picker"</font> then
set the_color to (choose from list color_text with prompt <font color = red>"Choose a colour:"</font> <font color = green>default</font> items {<font color = red>"Red"</font>})
set i to <font color = blue>1</font>
repeat with a_color in color_text
<font color = green>if</font> (a_color as list) = the_color then
set color_id to i
<font color = green>else</font>
set i to (i + <font color = blue>1</font>)
end <font color = green>if</font>
end repeat
try
set colorasHex to (item color_id of hex_Colors)
set colr_prompt to (<font color = red>"Colour choice: "</font> & (the_color as string) & <font color = red>" ("</font> & colorasHex & <font color = red>")"</font> & <font color = green>return</font> & <font color = red>"Enter a background colour (as a hexadecimal value):"</font>)
set backg_colr to (choose from list hex_Colors with prompt colr_prompt <font color = green>default</font> items (colorasHex as list))
<font color = green>if</font> (backg_colr as string) is not <font color = red>"false"</font> then
display dialog <font color = red>"Background colour choice: "</font> & (backg_colr as string)
end <font color = green>if</font>
end try
end <font color = green>if</font></font>[/code]hope it helps,
acur
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:49 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2