Script to copy text from clipboard to tab delimited text


I am needing to copy a lot of postal addresses from Safari and paste them into a spreadsheet. The problem is that each line of the postal address is typically on a new line on the webpages, so that when pasting them in to my spreadsheet (on Google Docs) the lines are pasted one under the other, when I need them to be all on the same line in separate cells. I can of course paste the full address into my spreadsheet and then manually cut and paste the individual cells so that they are entered on the same line, but I am wondering if there is a way of automating this using applescript. I presume the script would do the following:

  1. Copy selected text in Safari
  2. Transform separate lines in the copied text to one tab delimited line of text
  3. Copy this text to the clipboard

Then I could manually paste the text into the first cell on a new line of the spreadsheet and the rest of the text would follow in subsequent cells.

I would be grateful for some help in getting this working.



Copy selected text in safari, not sure how to do that because it won’t work javascript anymore. After that you can do it in one line of code when the selection is something like this

“john doe
mainstreet 123
12345 aCity”

the code would be something like where theContents is the data from safari:

set the clipboard to (do shell script "/bin/echo -n " & quoted form of theContents & " | tr '\\n' '\\t'")