Applescript: genera una nueva lista basada en la lista existente


3

mi script está generando una lista (número aleatorio de elementos) y para cada elemento me gusta agregar un color.

Puedo hacerlo manualmente:

> set myList to {{"demo", "#5cdf64"}, {"icloud.com", "#FFFF00"}, {"more
> random e.g", "#FF0000"}}

pero, ¿cómo puedo agregar un color diferente automáticamente a la lista y en función del número de elementos en la primera lista?

Sé cómo contar la lista principal y realizar una acción para cada elemento:

set listSize to count of myList

set theList to {"demo", "demo1", "demo2", "demo2"}
repeat with a from 1 to length of theList
    set theCurrentListItem to item a of theList
    -- Process the current list item

end repeat

Creo que casi estoy allí, lo único es que no estoy agregando sino reemplazando los elementos:

set theList to {"Demo", "ok", "blabla", "demo2"}
set ColortheList to {"5cdf64", "FFFF00", "FF0080", "FF1000"}
set myNewList to ""

repeat with a from 1 to length of theList
    set theCurrentListItem to item a of theList
    set myNewList to {item a of theList, item a of ColortheList}

end repeat

también trató

copy {item a of theList, item a of ColortheList} to myNewList

Estoy algo confundido con tu selección de color. ¿Desea el siguiente color en la lista o desea seleccionar un color al azar? ¿También quieres agregar al azar uno o más colores?
ʀ2ᴅ2

Lo siento, tengo una lista de palabras clave y quiero agregar colores diferentes para cada una de ellas. pero ya puedo crear la lista de colores y agregarlos a cada palabra clave de mi primera lista
Kevin

Dame un segundo y déjame terminar esta respuesta y dime si te entiendo correctamente.
ʀ2ᴅ2

Respuestas:


1

Si estas deseando myNewList Para devolver una lista de listas, creo que estás tratando de hacer:

set theList to {"Demo", "ok", "blabla", "demo2"}
set ColortheList to {"5cdf64", "FFFF00", "FF0080", "FF1000"}
set myNewList to {}

repeat with a from 1 to length of theList
    copy ({item a of theList, item a of ColortheList}) to the end of the |myNewList|
end repeat

return myNewList

Un poco de diversión con random number. Puede modificar la selección de color y luego agregar aleatoriamente a una lista:

set theList to {"Demo", "ok", "blabla", "demo2", "foobar"}

set colorList to {"5cdf64", "FFFF00"}
set colorLength to length of colorList

set myNewList to {}

repeat with a from 1 to length of theList
    set colorPick to random number from 1 to colorLength
    copy ({item a of theList, item colorPick of colorList}) to the end of the |myNewList|
end repeat

return myNewList

Si quieres un enfoque de cuerdas, prueba:

set theList to {"Demo", "ok", "blabla", "demo2"}
set ColortheList to {"5cdf64", "FFFF00", "FF0080", "FF1000"}
set myNewList to ""

repeat with a from 1 to length of theList
    set result to ({item a of theList, item a of ColortheList})
    set myNewList to myNewList & (result & " ")
end repeat

Lo anterior puede ser modificado en el result. Avísame si te estoy entendiendo o si necesitas algo diferente.

Al usar nuestro sitio, usted reconoce que ha leído y comprende nuestra Política de Cookies y Política de Privacidad.
Licensed under cc by-sa 3.0 with attribution required.