syntax for do shell script output displayed as list in applescript

Hi guys,

I am looking for the correct syntax for a

do shell script command in applescript,

where the results of the do shell script command are displayed as a list in applescript,

whereupon i can then choose one of these given results and move on from there, this is where i have gotten to:



User uploaded file

my issue is that the results are as follows when done in terminal:

User uploaded file

but when done in applescript i only see this:

User uploaded file

obviously the terminal results need to be handled in some special manner that i am unaware of,

to handle each line in the terminal results as a single option in my list. Anyone got any idea how to do this?

cheers

MacBook Pro, iOS 5.1

Posted on Mar 15, 2013 4:11 AM

Reply
1 reply

Mar 15, 2013 7:08 AM in response to Benjamyn

The problem is that the do shell script returns a string and choose list wants a list. So you have to convert the return value from a list to a string.


Applescript makes this fairly easy using the text item delimiter property. Text item delimiter (TID) determines how Applescript will convert from string to list or from list to string.


Here is an example using the command ls.


-- run the command

set a to (do shell script "ls")


-- save the current TID in oldtid and set the TID to return (the char we want to break the string at)

set {oldtid, AppleScript's text item delimiters} to {AppleScript's text item delimiters, return}


-- create list, b, from each text item in the string a. As the TID is set to the character return the string is broken at each

-- return

set b to every text item of a


-- Now set the TID back to want it was. Just a good pratice to get into so you don;t mess yourself up later on.

set AppleScript's text item delimiters to oldtid


-- now see than b is a list

choose from listb


You should be able to make the changes in your script. If you have problems cut and paste the script here (not a screen shot) so I can edit it.


regards

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

syntax for do shell script output displayed as list in applescript

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.