So I have this code:
set aList to {"one", "two", "three", "four"}
set aString to aList as text
which results in this output:
onetwothreefour
But what I want is this:
set aList to {"one", "two", "three", "four"}
-- do something here, I dunno what
which will result in this output:
{"one", "two", "three", "four"}
So, like, the literal representation of the AppleScript list code in the script.
I am open to a native AS solution, or something using ASObjC, or even a Unix command I can run via do shell script
.
Here’s the solution I have at the moment and it works but I kinda think it sucks.
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions
property jsScript : ".split('|||').map(w => `\"${w}\"`).join(',').replace(/^/, '{').replace(/$/, '}')"
set aList to {"one", "two", "three", "four"}
set saveTID to AppleScript's text item delimiters
set AppleScript's text item delimiters to {"|||"}
set aString to aList as string
set AppleScript's text item delimiters to saveTID
set scpt to quoted form of ((quoted form of aString) & jsScript)
set output to do shell script "osascript -l JavaScript -e " & scpt
log output
Which produces in SD’s event log:
(*{"one","two","three","four"}*)
Any suggestions?
Bonus round question!
Take this input:
{{"A","B","C"}, {"D","E","F"}}
and turn it into:
{"A","B","C";"D","E","F"}