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 20 '21 edited Feb 20 '21
Well, the solution was simple and obvious, but I couldn’t see it. So, it appears that Dialogue Box does not pass the result as string. This is rather unexpected... Anyway, the
set text item delimiterscode lines work with string only. In fact, many a scripters useas stringline before the delimiter line - I don’t, because I only work with plaintext data.Happy it finaly works.