Extracting Item/Word from a List

I am trying to build a list dynamically and then extract an element from it. This example with the list pre built works.

[AppleScript]
set mylist to {“08 2020”, “10 2020”}
display dialog mylist & return & item 1 of mylist as string
[/AppleScript]

This does not, in the example I have added brackets and tried to use text delimiters.

[AppleScript]
set mylist to “{”
set mylist to mylist & “08 2020” & “:”
set mylist to mylist & “10 2020” & “:”
set mylist to mylist & “}”
set PreDelim to AppleScript’s text item delimiters
set AppleScript’s text item delimiters to “:”
display dialog mylist & return & (word 1 of (mylist as string))
set AppleScript’s text item delimiters to PreDelim

 

Using word it returns 08 and item 0. Removing the brackets returns the same results also without text delimiters. The issue is the space between the month and year. The same issue if its text not numbers.

Thanks for any thoughts suggestions I'm stumped.

Not sure what you are trying to do in the first script.
A list is a data type in AppleScript. It is not a string or text.
That is why you cant build your list by concatenating string segments like you did in the second script.

Also “Display dialog” command expects text, not a list

here is a sample script to build your list

use scripting additions

set mylist to {} -- notice the curly braces are not in quotes
set end of mylist to "08 2020" -- each item in the list is text, the list itself is not text, but a LIST
set end of mylist to "10 2020" -- list now has 2 text items
display dialog item 1 of mylist

not sure what you are trying to do with the “Display Dialog”
and what are you trying to do with each element of the list?

First thanks very much for your help. I included the first script as I thought my issue had to do with i these brackets {, which I tried to do in my second script. Display dialog was added to see what my list produced. The trick of course as you pointed out was creating an empty list. I looked at the dictionary and searched on line obviously without dynamic as I just tried again and there is a post from DJ Bazzie Wazzie which I must have missed.

Thanks again:)

Ok, now we’re getting somewhere.

Display Dialog only shows text. If you want to see what’s in as list you have to convert list to text

like this

use scripting additions

set mylist to {} -- notice the curly braces are not in quotes
set end of mylist to "08 2020" -- each item in the list is text, the list itself is not text, but a LIST
set end of mylist to "10 2020" -- list now has 2 text items
set text item delimiters to return
display dialog mylist as text

if you want to have a user choose a specific item in a list then you would use

choose from list mylist

now what’s this about wanting to get words of each item like “08” of item 1?

Hi

I always seem to confuse when I post only part of what I am trying to achieve. In this case I am downloading data from the web and comparing it with files I have in a folder in fact a series of folders. Those files have been saved with dates and a reference.What I am doing (I hope) is comparing the files on the web with those I already have so I can download those I do not have. New files appear on a monthly basis.

The reference “08” was part of the string being returned using " word 1" (the month), until you told me how to do it, so now the whole date string is stored in the mylist variable.

Now I need to build nested repeats to check if the list items from the web exist in my folder.

Again thank you

Peter

Hi,

As I see. What you call myList in your script is actually the text returned by some command in your larger script. I will name it myText instead. The list is myList variable in my script:


set myText to "{"
set myText to myText & "08 2020" & ":"
set myText to myText & "10 2020" & ":"
set myText to myText & "}"

set AppleScript's text item delimiters to {"{", ":", "}"}
set myList to text items 2 thru -3 of myText

-- choose from list myList