Lists: choose 1 item, use corresponding item

Hi all,

I almost finished a script to produce a monthly flyer in Quark. Only have problems to change the color which is chosen by the user.
In the Quarktemplate there is a color spec named ˜MonthColor’ (Maandkleur), this one has to be changed depending on the month. (So january is PMS 021 Orange, February PMS 032 Red etc.)

This is what I have so far. The user can choos for a month, but how to get the color back?
(Anyway, probably this can be done better and neater then I did…)

Thanks in advance,
kjeld

--Name of color spec (Monthcolor) in QuarkXpress
set basicMonthColor to "Maandkleur"

--Corresponding PantoneColor for each Month
set the MonthColorlist to {{"januari", "PANTONE Orange 021 C"}, {"februari", "PANTONE Red 032 C"}, {"maart", "PANTONE Process Cyan C"}, {"april", "PANTONE 354 C"}, {"mei", "PANTONE Process Magenta C"}, {"juni", "PANTONE Orange 021 C"}, {"juli", "PANTONE Orange 021 C"}, {"augustus", "PANTONE Orange 021 C"}, {"september", "PANTONE Red 032 C"}, {"oktober", "PANTONE Process Cyan C"}, {"november", "PANTONE 354 C"}, {"december", "PANTONE Process Magenta C"}} as list
set Monthlist to {{item 1 of item 1 of MonthColorlist}, {item 1 of item 2 of MonthColorlist}, {item 1 of item 3 of MonthColorlist}, {item 1 of item 4 of MonthColorlist}, {item 1 of item 5 of MonthColorlist}, {item 1 of item 6 of MonthColorlist}, {item 1 of item 7 of MonthColorlist}, {item 1 of item 8 of MonthColorlist}, {item 1 of item 9 of MonthColorlist}, {item 1 of item 10 of MonthColorlist}, {item 1 of item 11 of MonthColorlist}, {item 1 of item 12 of MonthColorlist}}

--Userchoice: which month to produce 
set userChoice to (choose from list Monthlist with prompt "Which month to make?" without multiple selections allowed)

[EDIT]
You can find the final script with Quark template in the scriptbuilders section.
Or take a look in the Code Exchange section

Either I was too quick in posting, or I just saw the light.
This one is working for me, however if someone has suggestions to improve the script: please go ahead.

--Name of color spec (Monthcolor) supposed to be in your QuarkXpress document; spot color.
property basicMonthColor : "Maandkleur"

--Corresponding PantoneColor for each Month
property MonthColorlist : {¬
	{"januari", "Orange 021", "PANTONE Orange 021 C"}, ¬
	{"februari", "Red 032", "PANTONE Red 032 C"}, ¬
	{"maart", "Process Cyan", "PANTONE Process Cyan C"}, ¬
	{"april", "354", "PANTONE 354 C"}, ¬
	{"mei", "Process Magenta", "PANTONE Process Magenta C"}, ¬
	{"juni", "Orange 021", "PANTONE Orange 021 C"}, ¬
	{"juli", "Orange 021", "PANTONE Orange 021 C"}, ¬
	{"augustus", "Orange 021", "PANTONE Orange 021 C"}, ¬
	{"september", "Red 032", "PANTONE Red 032 C"}, ¬
	{"oktober", "Process Cyan", "PANTONE Process Cyan C"}, ¬
	{"november", "354", "PANTONE 354 C"}, ¬
	{"december", "Process Magenta", "PANTONE Process Magenta C"}} as list
property Monthlist : {{item 1 of item 1 of MonthColorlist}, {item 1 of item 2 of MonthColorlist}, {item 1 of item 3 of MonthColorlist}, {item 1 of item 4 of MonthColorlist}, {item 1 of item 5 of MonthColorlist}, {item 1 of item 6 of MonthColorlist}, {item 1 of item 7 of MonthColorlist}, {item 1 of item 8 of MonthColorlist}, {item 1 of item 9 of MonthColorlist}, {item 1 of item 10 of MonthColorlist}, {item 1 of item 11 of MonthColorlist}, {item 1 of item 12 of MonthColorlist}}

--Userchoice: which month to produce 
set newMonth to (choose from list Monthlist with prompt "Which month?" without multiple selections allowed) as text

--Userchoice: which corresponding color.
repeat with x from 1 to count of items in MonthColorlist
	if newMonth is (item 1 of item x of MonthColorlist) then
		set theNewColor to (item 2 of item x of MonthColorlist)
		set theNewColorName to (item 3 of item x of MonthColorlist)
	end if
end repeat

tell application "QuarkXPress Passport"
	tell document 1
		
		--Change Pantone of Month color
		set short name of color spec basicMonthColor to theNewColor
		set long name of color spec basicMonthColor to theNewColorName
		set name of color spec basicMonthColor to theNewColorName
	end tell
end tell
{theNewColor, theNewColorName}

One approach might be to loop back through your list. Add to the end of your original code to return userChoiceColor

repeat with i from 1 to count of MonthColorlist
	if userChoice is (item 1 of item i of MonthColorlist) then
		set userChoiceColor to (item 2 of item i of MonthColorlist)
	end if
end repeat

-N

Whoops.

You posted before I did!

HI, Kjeld.

Don’t forget to write in a little escape in case the user clicks on Cancel and newMonth is “false”. You could also (if you liked) put in an ‘exit repeat’ before the ‘end if’, to save the repeat from running on after the chosen month is found.

If the script’s always going to run on a machine where the months are shown in the user’s language, and the operating system will always be Panther or later, you could shorten the code to something like this:

--Name of color spec (Monthcolor) supposed to be in your QuarkXpress document; spot color. 
property basicMonthColor : "Maandkleur" 

--Corresponding PantoneColor for each Month 
property MonthColorlist : {¬ 
   { "januari" ,"Orange 021" ,"PANTONE Orange 021 C" }, ¬ 
   { "februari" ,"Red 032" ,"PANTONE Red 032 C" }, ¬ 
   { "maart" ,"Process Cyan" ,"PANTONE Process Cyan C" }, ¬ 
   { "april" ,"354" ,"PANTONE 354 C" }, ¬ 
   { "mei" ,"Process Magenta" ,"PANTONE Process Magenta C" }, ¬ 
   { "juni" ,"Orange 021" ,"PANTONE Orange 021 C" }, ¬ 
   { "juli" ,"Orange 021" ,"PANTONE Orange 021 C" }, ¬ 
   { "augustus" ,"Orange 021" ,"PANTONE Orange 021 C" }, ¬ 
   { "september" ,"Red 032" ,"PANTONE Red 032 C" }, ¬ 
   { "oktober" ,"Process Cyan" ,"PANTONE Process Cyan C" }, ¬ 
   { "november" ,"354" ,"PANTONE 354 C" }, ¬ 
   { "december" ,"Process Magenta" ,"PANTONE Process Magenta C" }}

set Monthlist to {}
repeat with thisItem in MonthColorlist
	set end of Monthlist to item 1 of thisItem
end repeat

--Userchoice: which month to produce 
set newMonth to (choose from list Monthlist with prompt "Which month to make?" without multiple selections allowed) as text
if (newMonth is "false") then error number -128

set {newMonth, theNewColor, theNewColorName} to item (month of date newMonth as integer) of MonthColorlist

Not necessarily better, I suppose, but cool. :cool:

& these where the answers I was waiting for.
Thanks guys. Looks way better now.

Kjeld

Well cool, Nigel - a great way to side-step the repeat loop! :cool::cool:

(Tongue very much in cheek, I was about to suggest incorporating a device to localize the month strings - but maybe we’ve played enough of that particular game! ;))

Just exploring the options, it occurred to me that it might be possible to dispose of the remaining repeat loop by separating the lists. (Again, no real improvement, but hey - why let that get in the way?)

property monthList : {"januari", "februari", "maart", "april", "mei", "juni", "juli", "augustus", "september", "oktober", "november", "december"}
property colorList : {{"Orange 021", "PANTONE Orange 021 C"}, {"Red 032", "PANTONE Red 032 C"}, {"Process Cyan", "PANTONE Process Cyan C"}, {"354", "PANTONE 354 C"}, {"Process Magenta", "PANTONE Process Magenta C"}, {"Orange 021", "PANTONE Orange 021 C"}, {"Orange 021", "PANTONE Orange 021 C"}, {"Orange 021", "PANTONE Orange 021 C"}, {"Red 032", "PANTONE Red 032 C"}, {"Process Cyan", "PANTONE Process Cyan C"}, {"354", "PANTONE 354 C"}, {"Process Magenta", "PANTONE Process Magenta C"}}

set newMonth to (choose from list monthList with prompt "Which month to make?")
if newMonth is false then error number -128
set {newMonth, newColor, newColorName} to newMonth & colorList's item (date (newMonth's item 1)'s month as integer)

Perhaps post this to Code Exchange, or wrap it up in a genuine script for all to use, and post on ScriptBuilders ? :stuck_out_tongue:

oh! Welcome back Kai! :smiley:

Mmmh. After all this is a bit less cool…
Working with month of date causes some problems. If the system language is different then the names in the list, it’s not working.
Besides that, you take away to the possibility to use the list for other purposes:
{“car”, “big”, “4 wheels”}, {“bike”, “small”, “two wheels”}

So I think looping back was the best option.

@ Ray: That was what I was planning to do. Will put it on scriptbuilders with the Quarktemplate and on code exchange without.

Kjeld

Cool! :smiley:

Thanks so much!

Why thank you, young man. :slight_smile: Another method, which I found convenient to use in my recently uploaded Scripts2Text script, is to number the options in the list. It looks OK and allows the chosen item’s position in the list to be determined very easily:

property monthList : {"1. januari", "2. februari", "3. maart", "4. april", "5. mei", "6. juni", "7. juli", "8. augustus", "9. september", "10. oktober", "11. november", "12. december"}
property colorList : {{"Orange 021", "PANTONE Orange 021 C"}, {"Red 032", "PANTONE Red 032 C"}, {"Process Cyan", "PANTONE Process Cyan C"}, {"354", "PANTONE 354 C"}, {"Process Magenta", "PANTONE Process Magenta C"}, {"Orange 021", "PANTONE Orange 021 C"}, {"Orange 021", "PANTONE Orange 021 C"}, {"Orange 021", "PANTONE Orange 021 C"}, {"Red 032", "PANTONE Red 032 C"}, {"Process Cyan", "PANTONE Process Cyan C"}, {"354", "PANTONE 354 C"}, {"Process Magenta", "PANTONE Process Magenta C"}}

set newMonth to (choose from list monthList with prompt "Which month to make?")
if (newMonth is false) then error number -128

set {newColor, newcolorName} to item (word 1 of beginning of newMonth) of colorList -- Automatic word-to-integer coercion.

This can be used on systems older than Panther and, of course, with choices other than months. (Rather perversely, Scripts2Text uses a repeat to number the options in the first place, but this does make sense in context!)

Yes. The original repeat would be far less bother! :wink:

:slight_smile: Indeed. ‘monthList’ was already compiled as a property in Kjeld’s second script. The nice thing about not including the months with the colours is that there’s no need to set ‘newMonth’ again in the set-by-list at the end of my suggestion.

PS.

I did mention that. Also, month-to-integer coercions are only possible in Panther or later. The alternative method mentioned above should work on any system.