Batch convert RTFD-PDF with date change

Discussion in 'Mac Programming' started by macstatic, Feb 3, 2017.

  1. macstatic macrumors 6502a

    Joined:
    Oct 21, 2005
    #1
    I have a bunch of (Textedit created) RTFD files (Rich Text Format with images) which I need to convert to PDF without too much hassle.

    Manually, I would open the file in Textedit, select "print" (File-Print) then click on the "PDF" button in the print-window and select "Save as PDF...".
    But I also don't want to forget when those files were originally created, so I'm torn between having an additional page added to the end of the PDF file with a text along the lines of "File originally created on xx.xx.xx" (where the "xxxxx" is of course the file's creation date/time, or simply having the creation date of the PDF file changed to the RTFD's creation date, then having the modification date set to when the file was converted.

    For the latter I've been messing around with EXIFtool in order to change a photo's file creation date so that could perhaps be used here as well.

    How do I proceed if I want to simply drag & drop an RTFD file and have it converted to PDF as described above?
     
  2. superscape macrumors 6502a

    superscape

    Joined:
    Feb 12, 2008
    Location:
    East Riding of Yorkshire, UK
    #2
    Mmmmm...

    I was about to smugly propose a few lines of AppleScript to get Pages to do the job for you. However, it looks like Pages no longer supports rtfd, and I don't see anything useful-looking in Word or TextEdit's scripting dictionaries.

    Not sure if you're going to have much luck on this one, I'm afraid.
     
  3. macstatic thread starter macrumors 6502a

    Joined:
    Oct 21, 2005
    #3
    Isn't there a way to simply way to just copy the keyboard shortcuts I'm using once the file has been dragged into Textedit? Here are the keyboard shortcuts I'd be using once an RTF file was open in Textedit:

    1) CMD-P (print)
    2) CMD-P (custom OSX shortcut for "Save as PDF")
    3) press "Save" button (to save PDF file)
    4) CMD-W (close window)
    5) go back to step 1 with the next open Textedit window

    Obviously I haven't added the step about either including the original file's date in the text document itself (i.e. "Original creation date of this file is xx/xx/xxxx") or changing the PDF file's creation date to that of the original RTF file as I don't know how to figure that part out yet.
     
  4. superscape macrumors 6502a

    superscape

    Joined:
    Feb 12, 2008
    Location:
    East Riding of Yorkshire, UK
    #4
    Yes, you *could* try to get the job done using interface scripting - that's to say simulating the actions of an actual user. Personally, I always end up in a world of pain when I take that route. If I'm lucky, I end up with a migraine and a rickety solution... if I'm lucky...

    That said, I can't see how you can get it done any other way so you might as well give it a try:

    https://developer.apple.com/library...nScriptingGuide/AutomatetheUserInterface.html
     
  5. organicCPU, Feb 10, 2017
    Last edited: Feb 11, 2017

    organicCPU macrumors 6502

    organicCPU

    Joined:
    Aug 8, 2016
    #5
    EDIT: Sorry, works for RTF, but nor for RTFD (with images)!

    That solution is a little bloated, but if you have LibreOffice or OpenOffice installed anyway, you could do the RTF to PDF conversion by a terminal command that involves LibreOffice in headless mode. You can find some more info here. It's also explained that cupsfilter, that would work for Plain Text and other files, isn't working anymore for RTF on OSs higher than Yosemite.
    Code:
    /Applications/LibreOffice.app/Contents/MacOS/soffice --headless --convert-to pdf /path/to/file.rtf
    There are some different methods describes here, but I find the LibreOffice method is doing quite good.

    For reading the creation date you could use exiftool on RTF files. Though I can recommend the "GetFileInfo" command. For setting the file dates on the PDF, you could use the "SetFile" command, that comes with the Developer Command Line Tools. More info is here.

    Just build an AppleScript or Automator action around all this and you're done.
     
  6. macstatic thread starter macrumors 6502a

    Joined:
    Oct 21, 2005
    #6
    Thanks for those suggestions. I will look into them as they might come in handy for other types of conversions later, but I decided to take up Superscape's suggestion and not get a migraine for this particular task ;)

    What I did was simply to use the Finder's search function to locate all files with the RTFD extension, open them up one by one, "print" them to PDF (I've created a CMD-P shortcut for "Save as PDF", so it's basically CMD-P and CMD-P again), then I zip compressed each original RTFD file in the same folder as each PDF file (so I can check the dates or revert to the original file if I should ever need that).

    While being able to display all RTFD files in one Finder window, being able to access each file's folder location might not be as straightforward, but if you first click once on the RTFD file in question, then look at the file path at the bottom of the Finder window you can double-click on the file's folder which will open it up. Once you're done compressing the original RTFD file (after creating a PDF out of it) you'll want to move on to the next file, so you simply click the back arrow in the Finder window to see the list again. search.png
     

Share This Page