I have a list of zip codes I want to use in my script.
I want to call something like zipcodes(1) and obtain first zip code from predefined list, call zipcodes(7) and obtain 7th zip code from the list.
How do I create a variable %zipcode% that I can use like that?
Thank you
If they’re numeric only, with no dashes, etc, then you can use Set Variable to Text to separating the zip codes with a comma (and optional space), then you can refer to them using Set Variable to Calculation with an index, like “MyZipCodes[2]”.
Otherwise, you could use Set Variable to Text putting each zip code on a new line. Then you could use a “For Each” action and a counter to loop through until you get to the one you want.
Or you could do it via AppleScript or JXA.
Let me know if you need further explanation.
rover233:
I have a list of zip codes I want to use in my script.
I want to call something like zipcodes(1) and obtain first zip code from predefined list, call zipcodes(7) and obtain 7th zip code from the list.
How do I create a variable %zipcode% that I can use like that?
Without more details, I'm having to make a bunch of assumptions here . . .
When you say "script" do you mean a real script like AppleScript or JXA, or a KM Macro?
Assuming a real script:
2016-09-20 16:37 CT (Tue)
Just posted an example macro/script:
## Macro Library Get Item from List by Position [Example]
####DOWNLOAD:
<a class="attachment" href="/uploads/default/original/2X/e/e1a8f9d135be42376e25f6fc568dafbd92450069.kmmacros">Get Item from List by Position [Example].kmmacros</a> (4.1 KB)
---
###ReleaseNotes
Simple example of how to read a list from a KM Variable, or a file, and then select the desired item by position in the list.
Created in response to this question:
https://forum.keyboardmaestro.com/t/how-to-create-and-call-varia…
Hi @DanThomas !
Thank you for you response.
How do I call MyZipCodes[2] using a variable instead of [2] ?
I tried this:
and it worked, however, when I tried to use Variable instead of [2] (in your example, it didn't work.
Thank you
When you're using a Calculation field, you never specify %Variable%, you just use the name of the variable. So the "to:" field would be:
ZipCodes[linenumber]