Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Converts a DOC or DOCX to a PDF with a right-click
#!/bin/bash
# Jacob Salmela
# 2016-03-12
# Convert annoying DOCX into PDFs with a right-click
# Run this as an Automator Service
###### SCRIPT #######
for f in "$@"
do
# Get the full file PATH without the extension
filepathWithoutExtension="${f%.*}"
# Convert the DOCX to HTML, which cupsfilter knows how to turn into a PDF
textutil -convert html -output "$filepathWithoutExtension.html" "$f"
# Convert the file into a PDF
cupsfilter "$filepathWithoutExtension.html" > "$filepathWithoutExtension.pdf"
# Remove the original file and the temporary HTML file, leaving only the PDF
rm "$filepathWithoutExtension.html" >/dev/null
done
@tsboh

This comment has been minimized.

Copy link

@tsboh tsboh commented Mar 22, 2019

from the manual of cupsfilter:

OPTIONS
       -D   Delete the input file after conversion.

so I suppose with that option line # 17 is not necessary

Thanks for the work!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment