St4rb0y St4rb0y - 8 months ago 59
AppleScript Question

Passing a Python list of strings to Applescript?

I have a Python script that evaluates certain directories on my hard-drive for criteria matching files. It returns a list of strings, containing the file names.

In Applescript, I call the Python script with

do shell script ""

If I print the list inside the Python script and run the script from Applescript, it appears as a single string (i.e. "['string1', 'string2', ..., 'stringX']") in the results dialog of the Script Editor App.

Does anybody know, how to pass this Python list to an identical Applescript list?



The most straightforward way to do this is to have the Python script print the list items on separate lines:


And in AppleScript, break those lines up into a list:

set AppleScript's text item delimiters to return
set list_of_files to text items of (do shell script "")