Write RTF format from text view

By calling “readRTFDFromFile:” on the text view, I can read in an rtf file.

But calling “writeRTFDToFile:atomically:” on a text view results in a new folder with the intended file name, and a file in that folder called TXT.rtf. Is this the only way to save rtf data from a text view?

-Joe

What is the problem with such behaviour? As far as I know, a “RTFD” file is a bundle, which mixes rtf text and attachments (eg, pictures)…
While it would be very easy moving “TXT.rtf” (if you only need the plain RTF source) and deleting the enclosing bundle, you can also:

set obj to text view 1 of scroll view 1 of window 1 --> for example
	set rtf to (call method "RTFFromRange:" of obj with parameters {{0, count (get content of obj)}})


set q to (choose file name default name "Untitled.rtf")
do shell script ("touch " & quoted form of POSIX path of q)
set f to (open for access q with write permission)
set eof of f to 0
try
	write rtf to f
end try
close access f

Thank you, that’s perfect. I just want RTF, since my text view doesn’t allow graphic attachments and the RTFD bundle isn’t necessary. I just don’t know enough about RTF to get the result you got, and saw no pure RTF writing method in the cocoa docs.

Again, thank you!

-Joe