Skip to content

Instantly share code, notes, and snippets.

@noniq
Created December 21, 2011 13:54
Show Gist options
  • Save noniq/1506136 to your computer and use it in GitHub Desktop.
Save noniq/1506136 to your computer and use it in GitHub Desktop.
Droplet for converting Word documents to PDF and adding a background.
property homeDir : POSIX path of (path to home folder)
on changeFileNameExtension(fileName, newExtension)
tell application "Finder" to set oldExtension to "." & name extension of alias fileName
set baseName to characters 1 thru ((offset of oldExtension in fileName) - 1) of fileName
return (baseName as string) & newExtension
end changeFileNameExtension
on convertWordFileToPdf(wordFile)
tell application "Finder" to set fileName to wordFile as string
tell application "Microsoft Word"
launch
open wordFile without add to recent files
set fileName to my changeFileNameExtension(fileName, ".pdf")
save as active document file name fileName file format format PDF
close active document
end tell
return alias fileName
end convertWordFileToPdf
on addBackgroundToPdf(pdfFile)
tell application "Adobe Acrobat Pro"
launch
open pdfFile
do script "
this.addWatermarkFromFile(\"/Macintosh HD" & homeDir & "lib/Buero-Organisation/CI/briefpapier_101013_pdf.pdf\");
"
save active doc
close active doc
end tell
end addBackgroundToPdf
on open of finderObjects
tell application "Microsoft Word" to set wordWasRunning to (it is running)
tell application "Adobe Acrobat Pro" to set acrobatWasRunning to (it is running)
repeat with inputFile in (finderObjects)
tell application "System Events" to set fileProperties to the properties of inputFile
if kind of fileProperties starts with "Microsoft Word" then
set pdfFile to convertWordFileToPdf(inputFile)
else
set pdfFile to inputFile
end if
addBackgroundToPdf(pdfFile)
end repeat
if wordWasRunning is false then tell application "Microsoft Word" to quit
if acrobatWasRunning is false then tell application "Adobe Acrobat Pro" to quit
end open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment