Get Lists or Dictionary from CSV Text

I occasionally need to get a list or lists, or a dictionary, from CSV text that contains two values per line. This shortcut gets one list:

One List from CSV.shortcut (21.9 KB)

The following shortcut gets two lists. The first Replace action returns a list of the text before the comma, and the second Replace action returns a list of the text after the comma.

Two Lists from CSV.shortcut (22.0 KB)

Getting a dictionary directly from comma- or tab-separated text is not possible, but this can be done with a JSON. My solution is kludgey, but I’ll work on this.

Dictionary from CSV.shortcut (22.3 KB)

I did not attempt to make a lists of lists, because it seems of little use in a shortcut.

I refined my CSV to Dictionary shortcut. It’s a bit shorter and does not use a repeat loop. It’s easily modified to work with TSV text.

CSV to Dictionary.shortcut (22.3 KB)

The following demonstrates making the JSON into a dictionary and getting a value from the dictionary.

All of the above shortcuts work only with CSV’s that have two values per line. For anything more complicated, a regular AppleScript should probably be used (here). However, if necessary, the above shortcuts can be edited to work, and the following is a simple example:

CSV to Lists.shortcut (22.9 KB)