
Exporting files from Lifecraft and importing to DayOne…
Converting 1700+ RTF files from my old Lifecraft program to plain text so it can be imported into the Day One app sounds simple—until you hit a datestamp snag. My files were named with dates like 5-16-17.rtf, and I needed those dates inside the TXT files as May 16, 2017. What started as a straightforward script turned into a debugging odyssey, but with some Python tweaks and Terminal commands (plus a nudge from my AI buddy, Grok), I got it sorted. Here’s the tale—and how you can do it too.
The Goal: From RTF (Lifecraft) to TXT (DayOne) with Style
I had 1700+ RTF files in /Users/daviddaniels/RTF_Files, each named with a date (e.g., 5-16-17.rtf for May 16, 2017). I needed to:
- Strip the RTF formatting to plain text.
- Add the date from the filename inside each TXT file as Date: May 16, 2017.
- Save them as TXT files (e.g., 5-16-17.txt) in /Users/daviddaniels/TXT_Files.
- Eventually combine them into one file (but that’s another story).
The First Attempt: A Solid Start
I kicked off with a Python script using striprtf to handle the RTF-to-text conversion. Here’s the base:
This worked, producing 5-16-17.txt with Datestamp: 5-16-17 inside. But 5-16-17 wasn’t cutting it—I wanted May 16, 2017.
The Hiccup: Datestamp Drama
To fancy up the date, I added datetime to parse and reformat:
I ran it in Terminal:
bash
Boom—error: No such file or directory: ’05/16/2017.txt’. The slashes in 05/16/2017 made Python think I wanted directories (/Users/daviddaniels/TXT_Files/05/16/). Grok flagged this: filenames can’t have slashes. Back to the drawing board.
The Fix: Splitting the Datestamp
We needed two datestamps:
- Inside the file: A pretty format like May 16, 2017.
- Filename: Something slash-free like 5-16-17.
After some trial and error, I settled on keeping the filename raw (from the RTF) and reformatting only the content. Plus, I swapped “Datestamp” to “Date” because that is what DayOne was looking for. Here’s the winning script:
python
How to Implement This Fix
Want to try it yourself? Here’s the step-by-step:
- Install Python:
- Check if you’ve got it: python3 –version in Terminal.
- No dice? Grab it from python.org. On macOS, the installer’s a breeze—just follow the prompts.
- Install striprtf:
- In Terminal:bash
pip3 install striprtf
- If that fails, try python3 -m pip install striprtf.
- In Terminal:bash
- Set Up Your Files:
- Dump your RTF files into a folder (e.g., /Users/yourname/RTF_Files).
- Create an output folder if it’s not there:bash
mkdir /Users/yourname/TXT_Files
- Save the Script:
- Open Terminal and launch TextEdit:bash
open -e /Users/yourname/convert_rtf.py
- Paste the script above.
- In TextEdit, hit Format > Make Plain Text (or Shift+Command+T).
- Save and close. Replace yourname with your actual username (e.g., daviddaniels for me).
- Open Terminal and launch TextEdit:bash
- Run It:
- In Terminal:bash
cd /Users/yourname python3 convert_rtf.py
- Watch it churn out lines like:
Converted: 5-16-17.rtf -> 5-16-17.txt Converted: 5-17-17.rtf -> 5-17-17.txt ...
- In Terminal:bash
- Check Your Work:
- Peek at a file:bash
head /Users/yourname/TXT_Files/5-16-17.txt
- You should see Date: May 16, 2017 followed by the text.
- Peek at a file:bash
The Payoff
After running this, I had 1700+ TXT files, each with a nicely formatted Date: May 16, 2017-style header, all named safely like 5-16-17.txt. No more directory errors, no more ugly 5-16-17 inside the files—just clean, readable dates. Later, I even combined them into one file, but that’s a tale for another post.
Lessons Learned
- Filenames Hate Slashes: Stick to dashes or underscores for file naming.
- Datetime is Your Friend: strptime and strftime can morph any date format if you know the pattern.
- Terminal + Python = Power: A few commands and a script can tame a thousand files.
Big thanks to Grok for spotting the slash issue and nudging me toward %B %d, %Y. Got a similar file-wrangling puzzle? Drop a comment—I’d love to hear how you’d tackle it!