Skip to content

Instantly share code, notes, and snippets.

Created February 28, 2023 18:53
What would you like to do?
AppleWorks and ClarisWorks files in a folder to PDF
Python script for Mac to convert AppleWorks and ClarisWorks files in a folder to PDF
Author: Mathias Beke
Date: August 2019
import os
import subprocess
import sys
def file_to_pdf(root, name):
file_to_pdf converts a single file to PDF
filename = os.path.join(root,name)
destination = root["/Applications/", "--headless", "--convert-to", "pdf", filename, "--outdir", destination])
def recursive_directory_to_pdf(path):
recursive_directory_to_pdf traverses directory recursively and converts all .cwk files to PDF
returns the number of converted documents
count = 0
for root, dirs, files in os.walk(path):
for name in files:
if name.endswith(".cwk"):
count += 1
file_to_pdf(root, name)
return count
if __name__ == "__main__":
print("AppleWorks to PDF converter\n")
process = subprocess.Popen('pgrep soffice', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
my_pid, err = process.communicate()
# Check if LibreOffice installed
if not os.path.exists("/Applications/"):
print("LibreOffice should be installed in 'Applications' folder")
# Check if LibreOffice not running
if len(my_pid.split()) > 0:
print("LibreOffice cannot be opened while running this script.\nQuit LibreOffice and run this script again.")
# Check if input specified
if len(sys.argv) <= 1:
print("Usage: python <path>")
path = sys.argv[1]
# Go!!!
count = recursive_directory_to_pdf(path)
print("converted " + str(count) + " files")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment