Creating a text file from a table view

I’ve got an application which uses a table view to store data. I’d like to offer the user an option to export its contents as a .txt file. Right now, I have the following code:


set theDataSource to data source of table view "tasks" of scroll view "tasks" of window "main"
set theData to (contents of every data cell of every data row of theDataSource as text)
set pathName to display save panel
set pathName to path name of save panel
set theFile to open for access (pathName as POSIX file) with write permission
write theData to theFile
close access theFile
return true

This sort of works, in that it does produce a .txt file with the contents of the table view. Unfortunately, the table view’s contents are all jumbled together. For example, the following was a result of running the script:

Web Designdemo7/13/06AssignmentWeb Designwow7/13/06AssignmentWeb Designcool7/13/06AssignmentWeb Designawesome7/13/06Assignment

Whereas what I’d like is this:

Web Design demo 7/13/06 Assignment
Web Design wow 7/13/06 Assignment
Web Design cool 7/13/06 Assignment
Web Design awesome 7/13/06 Assignment

Is there any way to get the script to produce a file formatted like that, as opposed to what it currently produces? If not, is there any way I could achieve this through “call method” with Cocoa?

Thanks so much! Your code does exactly what I was trying to accomplish.