Automated entry of password for MS Word files

Hello. I have to open a few thousand MS Word files (that are organized into several folders) that each require the same password and then answer "no" to the read-only prompt (each file was saved w/ a read-only prompt).


My hope is that I'd be able to create something with AppleScript or Automator that would enter the password and then answer "no" to the read-only prompt for all files in a specific folder.


The problem is that I have NO programming skills (I've never created an AppleScript or Automator function), and so, while I can find bits and pieces answering all of the above, I have no idea how to create a consolidated script/automatic function and don't even know how to run the function!


I know this is a big ask, but can anyone help me out? It would be a bit of a work lifesaver.


Thanks in advance.

Posted on Apr 24, 2022 10:34 PM

Reply
Question marked as Top-ranking reply

Posted on Apr 25, 2022 1:40 PM

Ordinarily, I'd shy away from scripting Microsoft Word, since Microsoft have done such a bad job of implementing AppleScript, but in this case it looks like they did the right thing and made it easy.


In this case, Microsoft added optional parameters to the open command that should address this kind of thing - it's as simple as:


set theDoc to (choose file)
tell application "Microsoft Word"
	open theDoc password document "blah" without read only
end tell


where 'blah' is the password on the document. Just paste this into a new Script Editor document and click Run.


The larger question at this point is how to implement this over a large number of files, and that's partly up to you. There are also a few parts missing - for example, you say you want to 'open a few thousand files'... all at once? that's going to put a significant drain on your system. Maybe you want to open them one at a time? close one before moving on to the next? maybe re-save it without a password? lots of options, but I can't think that opening a thousand documents all at once is really what you mean (although I may be wrong).


So options include running the script and it asking for the file to open.

Or using a droplet, so you drop a file on the script and it opens the file

Or maybe you want to process all the files in a folder at once?


Some more specifics about how you intend/expect this to work will help craft you a solution.

6 replies
Question marked as Top-ranking reply

Apr 25, 2022 1:40 PM in response to alsyli

Ordinarily, I'd shy away from scripting Microsoft Word, since Microsoft have done such a bad job of implementing AppleScript, but in this case it looks like they did the right thing and made it easy.


In this case, Microsoft added optional parameters to the open command that should address this kind of thing - it's as simple as:


set theDoc to (choose file)
tell application "Microsoft Word"
	open theDoc password document "blah" without read only
end tell


where 'blah' is the password on the document. Just paste this into a new Script Editor document and click Run.


The larger question at this point is how to implement this over a large number of files, and that's partly up to you. There are also a few parts missing - for example, you say you want to 'open a few thousand files'... all at once? that's going to put a significant drain on your system. Maybe you want to open them one at a time? close one before moving on to the next? maybe re-save it without a password? lots of options, but I can't think that opening a thousand documents all at once is really what you mean (although I may be wrong).


So options include running the script and it asking for the file to open.

Or using a droplet, so you drop a file on the script and it opens the file

Or maybe you want to process all the files in a folder at once?


Some more specifics about how you intend/expect this to work will help craft you a solution.

Apr 25, 2022 11:00 PM in response to alsyli

The script above didn't work; it ended w/ the Word icon bouncing in the dock and, when I clicked on the Word icon in the doc, it asked for the password. After I bit of searching, I combined things to create this:


set theDoc to (choose file)

set thePassword to "password"


tell application "Microsoft Word"

activate

ignoring application responses

open theDocs password document thePassword

end ignoring

end tell


try

tell application "System Events"

repeat until exists of window "Password" of application process "Word"

end repeat

click window "Password" of application process "Word"

click text field 1 of window "Password" of application process "Word"

keystroke thePassword

keystroke return

delay 0.2

click at {717, 403}

end tell

end try


This works! But it only will allow me to select one file at a time. Any ideas on how I can select multiple files?

Apr 25, 2022 3:28 PM in response to Camelot

Thank you so much for the response.


The files are organized into various folders. One folder = 1 yr's worth of a specific client's files. Each folder contains, at a maximum, 50-100 of the MS Word files that use the same password. I only need to work on the files in one folder at at time.


I would like to open all files in a single folder at once b/c, once the file is open, I need to add something to the header of each doc (I've created an MS Word macro for that) and then convert the file to a PDF. From a work flow perspective, I think it makes sense to open all the files in a single folder at once so that, when I close the file, I'm already in the "next" file that needs the same header modification and conversion (so I don't need to hunt around for the next file and won't accidentally miss a file).


All the PDFs from that folder (year) will then be consolidated into a single PDF to upload to a cloud-based service (and the Automator function already has a "Combine PDFs" function).


B/c the folders are organized by year, I would strongly prefer to work on all the files in a folder at once b/c I can complete a year at a time, which would make my workflow much more organized (I hope).


There's still a lot of "manual labor" that I need to do, but even "just" having an automated function to enter the password and click "no" for read only would dramatically cut down on the typing I have to do.


Let me know if more specifics would be helpful.

Apr 26, 2022 5:12 AM in response to alsyli

You have not mentioned what version of macOS you are using, but if you have installed macOS 12.3.1, then Apple has removed the long-standing Python distribution. What they overlooked is that the Python removal breaks the Automator Combine PDF action because it incorporates a Python script within the action bundle.


I contributed an AppleScript/Objective-C solution for combining PDFs that addressed that inoperable Automator action.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Automated entry of password for MS Word files

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.