The document “new.rtf” could not be opened. the ".rtf" file created from textedit is opening, but the ".rtf" file created in shell is not opening. could you provide more details on why this is happening and what can i do to solve this issue

the only difference I can see is size, even though both files are empty ".rtf" file created from text edit has some data, most probably headers or metadata, how can I simulate the same using touch

MacBook Air 13″

Posted on Jul 22, 2024 10:06 AM

Reply
Question marked as Top-ranking reply

Posted on Jul 22, 2024 10:21 AM

PS: GOT THE SOLUTION


I used textutil to create a rtf file

folder="JavaScript Result"

name="Provided Input"

extension=".rtf"

txt_extension=".txt"

if [ -e "$folder$name$extension" ] ; then

i=2

while [ -e "$folder$name $i$extension" ] ; do

let i++

done

name="$name $i"

fi

#touch "$folder$name$extension"


# Define the plain text content

txt_content="Hello, this is an RTF file created from the shell."


# Write the plain text content to a temporary text file

echo "$txt_content" > "$folder$name$txt_extension"


# Convert the plain text file to RTF using textutil

textutil -convert rtf "$folder$name$txt_extension" -output "$folder$name$extension"


# Remove the temporary text file

rm "$folder$name$txt_extension"


6 replies
Question marked as Top-ranking reply

Jul 22, 2024 10:21 AM in response to ganesh-lakshman

PS: GOT THE SOLUTION


I used textutil to create a rtf file

folder="JavaScript Result"

name="Provided Input"

extension=".rtf"

txt_extension=".txt"

if [ -e "$folder$name$extension" ] ; then

i=2

while [ -e "$folder$name $i$extension" ] ; do

let i++

done

name="$name $i"

fi

#touch "$folder$name$extension"


# Define the plain text content

txt_content="Hello, this is an RTF file created from the shell."


# Write the plain text content to a temporary text file

echo "$txt_content" > "$folder$name$txt_extension"


# Convert the plain text file to RTF using textutil

textutil -convert rtf "$folder$name$txt_extension" -output "$folder$name$extension"


# Remove the temporary text file

rm "$folder$name$txt_extension"


Jul 22, 2024 10:47 AM in response to ganesh-lakshman

Rich Text Format is a Microsoft format with varying definitions, and is not one I’d generally recommend for swapping files around.


Sequential text files are far more common, whether with ASCII or UTF-8 or other encoding.


While echo can create a sequential text file, it cannot create an rtf file.


I’m not aware of any native command-line tools that can particularly create or work with rtf files either, though some GUI apps including LibreOffice can. Other scripting languages can likely work with RTF as well; AppleScript or Perl or Python all seem likely to have some RTF capabilities either integrated or available.


Related:

https://apple.stackexchange.com/questions/251466/how-to-use-applescript-to-create-a-new-rich-text-format-file-from-clipboard-text#251490


For formatting text at the command line, maybe markdown tools, or using groff / troff / etc, or using TeX or LaTeX.

Jul 22, 2024 2:53 PM in response to VikingOSX

VikingOSX wrote:

Apple removed Groff, troff, and their associated DWB tools from Ventura and later. It was a UNIX operating system until they did that… 🧐 I don't create RTF anything…


Yep. And TeX and LaTeX support and command-line markdown support were all never present.


RUNOFF support is less widely available too, so I skipped mention of that one, and a few others.


Various of these can be installed from Homebrew or MacPorts. Or choices and options elsewhere.


Most I’ve dealt with rtf lately involved dragging some data out of a provided rtf file.


This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

The document “new.rtf” could not be opened. the ".rtf" file created from textedit is opening, but the ".rtf" file created in shell is not opening. could you provide more details on why this is happening and what can i do to solve this issue

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.