personal blog of Jonathan Fretheim

I got tired of copying a column of stuff from Excel, opening BBEdit, doing a find and replace to convert a bunch of lines into one block of comma-delimited text, selecting it all, copying again, and then finally pasting. I felt like I was that chump using an old fashioned blanket on the snuggie commercial.

So, I wrote this AppleScript.

clipboard newlines to commas and paste


  1. Copy a column of stuff (from Excel, Numbers, anything really)
  2. Go to where you want to paste it as comma-delimited
  3. Invoke the script!

On my system, I run it with a keystroke trigger defined in Quicksilver. But you could use LaunchBar…or activate it from the scripts menu. By the way, if you want a system-wide scripts menu, here is a page that describes a nice way of activating a bunch of menu extras in OS X.

[EDIT 11/16/2010: The script has been updated and is now much simpler. Rather than writing to a temp file, everything's done with one pipelined shell script.

Additionally, this version squeezes together multiple consecutive newlines and replaces them with one comma. If you need to preserve those as consecutive commas, remove the -s option from each of the two tr statements.

It also removes any trailing comma from the result. If you don't want it to do this, remove the sed section.

do shell script "pbpaste | tr -s '\\n' ',' | tr -s '\\r' ',' | 

     sed -e 's/,$//' | pbcopy"


Post a comment