How to turn a list into comma-separated values on Mac

Replace every line break with a comma and a space. In Clip Text Transform, copy the list and pick Lines to CSV row, a ready-made script you add once from the Script Library. For quotes around each value, run Wrap each line in double quotes first. Watch for a line break after the last value.

You have a column of values — IDs from a spreadsheet, names from a log, tags from a document — and you need them on one line, separated by commas: for a SQL query, a JSON array, a config file or a message. Typing the commas by hand is fine for five values and miserable for fifty — and one missed comma breaks the query.

Which way to use. Plain values, one line: Lines to CSV row. Values in double quotes, one line: Wrap each line in double quotes, then Lines to CSV row. Values in single quotes, one per line, for a SQL IN (…) list: Lines to SQL IN list on its own — see the limits below.

The built-in way: replace breaks with commas in Pages

Pages, Apple's word processor, can do this if you have it installed. Its Find & Replace searches for breaks by code, and whatever you type in the replace field goes in their place.

  1. Paste the list into a Pages document, one value per line.
  2. Open Find & Replace and search for \n — Pages's code for a paragraph break. Each value on its own line counts as a paragraph, so this finds the break after every value.
  3. Type a comma and a space in the replace field, replace all matches, and copy the line back out.

If the list ended with a break, the line now ends with a comma — delete it before you paste.

Do it from the menu bar with Clip Text Transform

The first time, add the script: click the Clip Text Transform icon, choose Manage Custom Scripts…, open the Script Library, select Lines to CSV row and click Add. From then on it sits in your menu like any other item.

Then, each time: copy the column, pick Lines to CSV row, paste.

Before
London
Paris
Rome
After

London, Paris, Rome

Empty lines in the middle of the list are skipped rather than turned into empty values, and a list copied with Windows-style line endings comes out the same.

Under the hood it's an ordinary find & replace rule — Find \R+ (one or more line breaks of any kind), Replace ,  — so you can open it, see exactly what it does, and change it. If you need a different separator, build a rule like this yourself — type a sample under Testing in the script editor and the result updates as you type.

Add quotes around each value

For SQL strings or a JSON array, each value usually needs quotes. That's two scripts in a row — both from the Script Library:

  1. Copy the column and pick Wrap each line in double quotes. Every line gets its quotes; the result goes back to your clipboard.
  2. Pick Lines to CSV row. The quoted lines are joined.
  3. Paste.
Before
London
Paris
Rome
After

"London", "Paris", "Rome"

Two clicks instead of one, but no retyping and no quote missed.

Double quotes are what JSON strings use: put the line between square brackets to make an array. The scripts don't escape anything, so a value that itself contains a double quote needs fixing by hand. SQL usually wants single quotes around strings — for that, use Lines to SQL IN list on its own, paste the lines between the parentheses of IN ( … ), and delete the comma after the last value (more on that below).

What to watch out for

The last line matters. If the copied column ends with a line break, the result ends with a comma and a space: London, Paris, Rome, . The quoted version behaves the same way and ends in "Rome",  — so check the end of the line whichever way you joined it. Delete the tail before you paste, or copy the column without the line break after the last value.

Don't chain Lines to SQL IN list into Lines to CSV row. Lines to SQL IN list puts each value in single quotes with a comma after it, one per line — 'London', / 'Paris', — including a comma after the last value. Run Lines to CSV row on that and you get double commas: 'London',, 'Paris',, 'Rome',. Use Lines to SQL IN list on its own when a multi-line list is what you want, and remove the final comma.

Lines to CSV row joins everything. Every line break becomes a comma — including breaks between separate groups of values. Copy one list at a time.

Values aren't changed. The scripts add commas and quotes around what's on each line; they don't trim or rewrite the values themselves.

The joining happens on your Mac, and the list you copy stays on your Mac. Details are in the Privacy Policy.

Need other quick fixes for copied text? Browse everyday text tasks on your Mac.

Download Clip Text Transform — free for macOS

Free, no sign-up, your text stays on your Mac.

Download for macOS

Requires macOS 13.3 or later.

See everything it does