Skip to content

Instantly share code, notes, and snippets.

@paultopia
Created April 9, 2016 15:14
Show Gist options
  • Save paultopia/dbbaea075b5bba73d0ec77f58384d52b to your computer and use it in GitHub Desktop.
Save paultopia/dbbaea075b5bba73d0ec77f58384d52b to your computer and use it in GitHub Desktop.
# convert a directory full of M$word .docx files to PDF
# REQUIREMENTS:
# 1. Only works on Mac.
# 2. Assign the variable USERNAME to your home directory
# 3. Requires the PDFwriter printer driver, get it here: https://sourceforge.net/projects/pdfwriterformac/
# 3.5 (might require PDFwriter to be your default printer; on my machine it's the only printer, so I haven't tested with any other config
# 4. Requires the launch and appswitch apps from the wonderful Nicholas Riley, get them here: http://sabi.net/nriley/software/
import glob, os, time
homedir = os.getcwd()
pdfdir = '/users/shared/PDFwriter/%s' % USERNAME
for docfile in glob.glob("*.docx"):
printstring = 'launch -p %s' % docfile
os.system(printstring)
os.chdir(pdfdir)
for x in range(90):
time.sleep(1)
if glob.glob('*.pdf'):
break
filename = glob.glob('*.pdf')[0]
moveme = 'mv "%s" "%s/%s.pdf"' % (filename, homedir, docfile[:-5])
os.system(moveme)
os.chdir(homedir)
os.system('appswitch -qi com.microsoft.Word')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment