{"id":171,"date":"2009-04-05T07:59:23","date_gmt":"2009-04-05T12:59:23","guid":{"rendered":"http:\/\/www.jaimerios.com\/?p=171"},"modified":"2009-04-05T07:59:23","modified_gmt":"2009-04-05T12:59:23","slug":"print-to-pdf-with-applescript-and-microsoft-word","status":"publish","type":"post","link":"https:\/\/jaimerios.com\/?p=171","title":{"rendered":"Print to PDF with AppleScript and Microsoft Word"},"content":{"rendered":"<p>Recently, I needed to automate printing a Word document to a PDF file and have it saved to a predefined location. There were some good articles on the web about how to do the printing part, or the PDF part but not how to save the output.<\/p>\n<p>So, here&#8217;s my stab at printing a Word document to a PDF file in a known location:<\/p>\n<pre lang=\"AppleScript\">-- This AppleScript will open up our Word doc and save it as a PDF\n\nset myDoc to \"\/Users\/jaimerios\/Documents\/Developer notes.doc\"\nset pdfSavePath to \"\/Users\/jaimerios\/Documents\/PDFs\/\"\n\ntell application \"Microsoft Word\"\n\tactivate\n\topen myDoc\nend tell\n\ntell application \"System Events\"\n\ttell process \"Microsoft Word\"\n\t\t-- Press command+p to open our print dialog\n\t\tkeystroke \"p\" using command down\n\n\t\t-- Let's make sure our print dialog is up\n\t\trepeat until exists window \"Print\"\n\t\tend repeat\n\n\t\t-- Click the PDF menu button\n\t\tclick menu button \"PDF\" of window \"Print\"\n\n\t\t-- Make sure the menu is up\n\t\trepeat until exists menu item \"Save as PDF\u2026\" of menu 1 of menu button \"PDF\" of window \"Print\"\n\t\tend repeat\n\t\t-- Select the \"Save as PDF\" menu item\n\t\tclick menu item \"Save as PDF\u2026\" of menu 1 of menu button \"PDF\" of window \"Print\"\n\n\t\t-- Make sure the save dialog is visible\n\t\trepeat until exists window \"Save\"\n\t\tend repeat\n\n\t\t-- Press command+shift+g to show the \"Go\" drop down sheet\n\t\tkeystroke \"g\" using {command down, shift down}\n\t\t-- Set our location field to our pdfSavePath\n\t\tset value of text field 1 of sheet of window \"Save\" to pdfSavePath\n\t\t-- Now click the Go button\n\t\tclick button \"Go\" of sheet of window \"Save\"\n\n\t\t-- Now that we are in our desired folder, set the file name and save\n\t\tset value of text field 1 of window \"Save\" to \"Special Developer Notes.pdf\"\n\n\t\tclick button \"Save\" of window \"Save\"\n\tend tell\nend tell<\/pre>\n<p>Now the only limitation to this script is that it doesn&#8217;t handle the condition where the PDF file might already exist in our output location.<\/p>\n<p>I have to give credit to the original author who came up with tis script. Their AppleScript code is located <a href=\"http:\/\/www.ehmac.ca\/mac-ipod-help-troubleshooting\/48924-applescript-code-request-print-pdf-function-2.html\" target=\"_blank\" rel=\"noopener\">at this website link.<\/a><\/p>\n<p>Well, I hope this helps you and if you have any comments to make this script better, let me know.<\/p>\n<p>Happy coding!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently, I needed to automate printing a Word document to a PDF file and have it saved to a predefined location. There were some good articles on the web about how to do the printing part, or the PDF part but not how to save the output. So, here&#8217;s my stab at printing a Word &#8230; <a title=\"Print to PDF with AppleScript and Microsoft Word\" class=\"read-more\" href=\"https:\/\/jaimerios.com\/?p=171\" aria-label=\"Read more about Print to PDF with AppleScript and Microsoft Word\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[67,301,348,501],"class_list":["post-171","post","type-post","status-publish","format-standard","hentry","category-coding","tag-applescript","tag-microsoft-word","tag-pdf","tag-word"],"_links":{"self":[{"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/posts\/171","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/jaimerios.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=171"}],"version-history":[{"count":0,"href":"https:\/\/jaimerios.com\/index.php?rest_route=\/wp\/v2\/posts\/171\/revisions"}],"wp:attachment":[{"href":"https:\/\/jaimerios.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=171"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/jaimerios.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=171"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/jaimerios.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=171"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}