AppleScript Droplet - Save Word docx (with links to Excel Workbooks) as PDFs into a Designated Folder


Joined
Feb 18, 2022
Messages
3
Reaction score
0
Hi everyone,

I’m at the start of a huge learning curve with Applescript and feel way out of my depth. I’m sure what I’m trying to achieve is possible but I don’t know how to go about it.

I am trying to create a Droplet that will convert Word documents into pdf files and save them into a designated folder, not the same folder as the Word documents. Seems straightforward enough.

Google showed me a script that will save pdfs into the same folder as the Word documents but that’s not what I require and I don’t know how to change it.

Another problem is the script only works with straight forward Word documents. By that I mean the files I’m working with all have multiple links to external data in an Excel workbook. The links are set to automatically update. When the document opens, a prompt appears requiring a response. I don’t know how to write a script that answers the prompt. See image.
Screenshot 2022-02-18 at 20.13.31.png


All the files open but the script fails at the prompt, so I have to manually click ‘Yes’ for each one.

Ideally the script would answer ‘Yes’ (not ‘No’) to the prompt for each file in the list and then save a pdf into my designated folder before closing.

Another problem. The automatic update setting, triggers another prompt on closing the document, asking if I want to save changes or not; ideally yes. I don’t know how to write a script to answer this prompt either.

Screenshot 2022-02-18 at 20.21.57.png


Turning the ‘Update: automatically’ option on and off gets around the prompts but it’s not really a viable solution. In short, I looking for a Droplet that can answer both prompts appropriately and also save a pdf to my designated folder.

Please, if anyone can help me?
 
Ad

Advertisements

Joined
Feb 18, 2022
Messages
3
Reaction score
0
Hi, here it is.

tell application "Finder"


set input to selection


end tell





tell
application id "com.microsoft.Word"


activate


set view type of view of active window to draft view





repeat with aFile in input


open aFile


set theOutputPath to ((aFile as text) & ".pdf")


repeat while not (active document is not missing value)


delay 0.5


end repeat


set activeDoc to active document


save as activeDoc file name theOutputPath file format format PDF


close active document saving no


end repeat





end tell
 
Joined
Jan 25, 2017
Messages
1,161
Reaction score
86
You can 'Tab' using
tell application "System Events" to key code 48

and 'Enter' with

tell application "System Events" to key code 36
 
Ad

Advertisements

Joined
Feb 18, 2022
Messages
3
Reaction score
0
You can 'Tab' using
tell application "System Events" to key code 48

and 'Enter' with

tell application "System Events" to key code 36

Thanks for your reply. I've found another script that I'm now running in Automator as a Quick Action, can you show me where in the script to add your script?

property theList : {"doc", "docx"}
on run {input, parameters}
set output to {}
tell application "Microsoft Word" to set theOldDefaultPath to get default file path file path type documents path
repeat with x in input
try
set theDoc to contents of x
tell application "Finder"
set theFilePath to container of theDoc as text

set ext to name extension of theDoc
if ext is in theList then
set theName to name of theDoc
copy length of theName to l
copy length of ext to exl

set n to l - exl - 1
copy characters 1 through n of theName as string to theFilename

set theFilename to theFilename & ".pdf"

tell application "Microsoft Word"
set default file path file path type documents path path theFilePath
open theDoc
set theActiveDoc to the active document
save as theActiveDoc file format format PDF file name theFilename
copy (POSIX path of (theFilePath & theFilename as string)) to end of output
close theActiveDoc
end tell
end if
end tell
end try
end repeat
tell application "Microsoft Word" to set default file path file path type documents path path theOldDefaultPath
return output
end run
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top