Writing AppleScript to change a TextEdit document from .rtfd file to .rtf

applescripttextedit

I am using TextEdit and need the document to save as a .rtf, but when I am copying and pasting the data over, since there are small images and thumbnails, it will always save as .rtfd.

I am currently going through the process of doing this manually, but when dealing with 50+ documents, going into the Get Info area, setting the proper extension, then saving that file again takes time. I do not need the images to be there, but going through and removing manually is also not a good option.

I am currently trying to learn AppleScript and using Script Editor, but wanted to see if in the meantime anyone had any ideas here or have a script that does this?

Best Answer

The @user3439894 comment provides a better solution but since this is tagged as applescript, here is an applescript answer.

Will prompt user to choose one or more rtfd, copy them to the desktop, turn them into actual folders, extract each one's text/rtf component to the desktop, and trash the unwanted bits. I don't know how you actually get the target files so I went with 'choose' and stuck to using the desktop as the workplace.

use scripting additions
-- Choose one or more rtfd
set aFilList to {}
set aFilList to (choose file with multiple selections allowed)
tell application "Finder"

    repeat with aFil in aFilList

        -- copy rtfd to desktop; collect name information       
        set dFil to duplicate aFil to (path to desktop folder)
        set {adNam, ddNam, dwXt} to {displayed name of aFil, displayed name of dFil, ".rtf"}
        --> {"filename", "filename 2", ".rtf"}, or {"filename", "filename copy", ".rtf"}

        -- Remove 'd' from extension to reveal as type:folder
        set name of dFil to ddNam & dwXt
        set dFil to ((path to desktop) & ddNam & dwXt as text)

        -- Move rtf to desktop and rename; trash intermediary files
        move file "TXT.rtf" of alias dFil to (path to desktop) with replacing
        set oFil to (path to desktop) & "TXT.rtf" as text
        set name of alias oFil to (adNam & dwXt)
        delete aFil
        delete dFil

    end repeat
end tell