Does anybody know is there a way to convert a .doc or docx in a single click to a .pdf who is stored at the same place with the same tags in the database?
Very offen we editing a word and the convert it to a pdf before we send it. Does anybody has a idea to deal with that a quick and easy way?
How do you currently convert the document to PDF? The best solution is probably to open the document with Word or Pages and to print the document to a PDF but that’s hardly scriptable.
You’ll not be able to put this into the contextual menu, but you could take one of those starting points and wrap a DEVONthink script around it that would do the bit about “store in the same place [i.e., the source group] with the same tags”. Your final script could be installed into DEVONthink’s Scripts menu or added to the toolbar. Or you could modify the Automator version and make it into a service executable from DEVONthink’s Services menu.
You’re right, it’s doable as there’s already a script on my disk dating back to January
-- Convert Word documents to PDF
property extensionList : {"doc", "docx"}
tell application id "DNtp"
set theInput to {}
set theSelection to the selection
repeat with theRecord in theSelection
set theFile to (path of theRecord) as POSIX file
set theDoc to theFile as alias
tell application "Finder"
set theFilePath to container of theDoc as text
set ext to name extension of theDoc
if ext is in extensionList then
set theName to name of theDoc
set theFilename to characters 1 through ((length of theName) - (length of ext) - 1) of theName as string
set theFilename to theFilename & ".pdf"
tell application "Microsoft Word"
set theOldDefaultPath to get default file path file path type documents path
set default file path file path type documents path path theFilePath
open theDoc
set theActiveDoc to the active document
set theFilePath to (path to desktop folder) as string
set default file path file path type documents path path theFilePath
save as theActiveDoc file format format PDF file name theFilename
close theActiveDoc
set default file path file path type documents path path theOldDefaultPath
end tell
set theConvertedPath to (theFilePath & theFilename as string)
end if
end tell
set theConvertedRecord to import POSIX path of theConvertedPath to (parent 1 of theRecord)
if exists theConvertedRecord then tell application "Finder" to delete theConvertedPath
end repeat
end tell
There is one edge case when the script will fail. Word saves documents divided by section breaks into separate pdfs. In that case only the pdf with the first section will be imported.
set theConvertedRecord to import POSIX path of theConvertedPath to (parent 1 of theRecord)
add the line
set tags of theConvertedRecord to tags of theRecord
and all the tags from the word document will be copied to the pdf.
Otherwise the script worked well for me. There will be a copy of the pdf in the trash. This is nothing to worry about. Word has to save the file before it can be imported into DT. The pdf is imported into the same group as the original pdf which is where you should look for it.
In Word 2016 you have to go through a serious of pop up boxes authorising access to the Desktop before the script will work for the first time.
Can we use you as a character witness in some other threads, where the prevailing opinion is that “the devs are lazy” and the “forum members hostile”?
Since the last update it doesn’t work anymore. But i have no idea where to check first, why it does’t work anymore. But of course you can use my case. The devs are definitely not lazy!
You didn’t mention what the “last update” was – DEVONthink, OS X, Word, something else? But I ran Criss’s script through Script Debugger and this statement fails:
set theOldDefaultPath to get default file path file path type documents path
with an AppleScript compiler error “Expected end of line but found class name.” Typically vague Apple error message. I’m running Word 15.16 (151105), and the Word dictionary appears to support this statement, but it actually doesn’t.
Anyway, looks like the script is broken over here because something broke Word’s AppleScript support.
The failed statement is merely the first broken statement in the script – there might be others.
I wonder if I have have a potential conflict between Word 15.16 running on the OS X side and Word 2013 running under a VM – Parallels is sharing OS X/Windows 10 apps both directions. Script Debugger and Apple Script Editor each kept trying to launch the Windows instance of Word.
Mhh i have the same status like Frederick, and there it works. Strange!
Word: 15.16
Mac: 10.11.2
DT: 2.8.8
Has the Problem have to come from another 3rd Party on my Computer… Puh… hard to find out. Any idea where to start to check. The problem is, i can’t really say what change between the point of working and not working.