r/applescript • u/d1squiet • Feb 01 '21
Bash/Applescript – dealing with comma delimited results
OS X 10.14.6
I am writing a bash script which calls Applescript to create a dialog box (using the Dialog Box Plus Toolkit). Everything works great, but there are a couple fields where the user enters a string in the dialog box.
When Applescript passes back the results of the dialog box to bash, it does it as a comma delimited string. Something like:
true, false, Bob Smith, EngineerIt all works okay unless someone types a comma in the entry fields. Then instead of four results, I will get five or more results, like:
true, false, Smith, Bob, EngineerIs there a way to catch commas in the dialog box? Or to make AppleScript use a different delimiter in the the dialog box results?
EDIT: I believe this is solved. /u/SvilenOvcharov illuminated the "set text item delimiter" command in Applescript for me. Then one has to make sure to return the value as a string. So "return <variableList>" seems to always send commas to bash, but "return <variableList> as string" will send the the list delimited by whatever you set it to. The "as" command in Applescript is not intuitive to me. Since Applescript is clearly sending the variable out as a text-string, it seems odd to have to specify it.
View all comments
Show parent comment
2
u/htakeuchi Feb 02 '21
Ok...
Now that I have this a better thought ...
You need to run each result you get through the “tr -d ,” command
So as an example:
set theResult to “Hello, How are you?” set theFinalResult to do shell script “echo ”& theResult & “| tr -d ,” return theFinalTest
This will remove the comma from the variable ... effectively giving you “Hello How are you?” As a result
What you will need to do now is adapt the command to run on each one if your results to make sure it removes them all prior to passing them to bash