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
1
u/SvilenOvcharov Feb 02 '21 edited Feb 02 '21
Another idea, you need first to set what is the old delimiter of the particular string in question (in our case comma) and only then try to replace it. Try setting as delimiter not comma, but rather this part of the string:
and then using the script replace it with this:
It's a semi-colon, followed by a space (normal one).
Or replace with this, if somehow preserving the comma is important:
It's a comma, followed by a space (normal one).
Although, it will not set any delimiter where there is ONLY comma, without quotes.
Disclaimer: Again, I know nothing about the Dialogue Box Plus thingy, so if it messes something I cannot help.
Note: there is space there and I hope the Dialogue Box Plus thingy doesn't pass whitespace. In such a case, the script is not going to work, because AppleScript distinguishes between normal and whitespace and you'll need to replace the whitespace first.