Can't use shell script result

When using this line


set theItems to (do shell script "cat /some/file.txt")
display dialog theItems  -- This returns {"item 1", "item 2", "item 3"}
set content of table view "table1" of scroll view "cspathAD" of window "paths" to theItems

But it doesn’t work. However, if I do this, it works:


set theItems to {"item 1", "item 2", "item 3"}
display dialog theItems  -- This returns {"item 1", "item 2", "item 3"}
set content of table view "table1" of scroll view "cspathAD" of window "paths" to theItems

It seems that passing the result from “do shell script” back into the script treats the whole result as quoted or something.
For example, in the first example above, adding curly braces to theItems will actually put the whole string {“item 1”, “item 2”, “item 3”} into the first line of the table view, like it’s a quoted string:

set content of table view "table1" of scroll view "cspathAD" of window "paths" to {theItems}

I’ve tried setting the variable as text, as unicode text, as string, as item, paragraphs of, etc etc, and it just won’t work. Any ideas?

Thanks!
:frowning:

The result of a “do shell script” command is always a string.

Are you saying that your actual text file contains this:

Yes, for all intents and purposes. Of course, if the curly’s are in the way in the text file, I can remove them.

You’ll have to find a way to coerce that string to a list. I know that’s been discussed before, but I can seem to find the right thread.

If you’re the person creating this text file, you could also consider storing your values in a way that would be easier to read later.

Edit: You can try something like this:

do shell script "cat /some/file.txt"
set temp to result

set ASTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {"\", \""}

set temp to every text item of temp
set temp's first item to text 4 thru -1 of temp's first item
set temp's third item to text 1 thru -3 of temp's third item

set AppleScript's text item delimiters to ASTID

set content of table view "table1" of scroll view "cspathAD" of window "paths" to temp