how to open a password protected file from Applescript?

I see that being able to open password protected iWork files from AppleScript is now possible from 11.0 and up.. I am running Keynote 11.1 and the dictionairy for Keynote, Pages and Numbers do not specicfy how to open a password protected document. It only shows how to remove the password once the document is opened. Has anyone had any luck opeiong a password protected iWorks file from Applescript?

Posted on Jun 17, 2021 10:47 AM

Reply
14 replies

Jun 17, 2021 1:32 PM in response to BMayhem

If the password is set by you and remembered in your keychain, then as long as the Keynote document resides in your home directory, it will just open normally in Keynote v11.1 by getting the password from the keychain. Otherwise, when you attempt to open the password-protected Keynote document, you will get a password entry dialog which Keynote has no means to autofill by any AppleScript effort:


Keynote v11.1, macOS 11.4

Jun 24, 2021 9:25 AM in response to KingPeter223

I think a script will start to open a document. But as far as I can tell it won't "feed in" a password, perhaps because that would render security measures meaningless.


Instead the user is prompted to enter a password (perhaps via Touch ID if the password is saved in a keychain) and then a script can remove the password and save the file.



SG

Jun 17, 2021 2:45 PM in response to BMayhem

Yes, there is Keynote AppleScript dictionary support to set or remove a password from a document. In either case, you would need to provide a plain-text password in your AppleScript which is not sensible, or capture the output of a display dialog with a hidden answer and then pass that variable to either the set or remove password verbs. I haven't tested that to see if it would work.


Sure you can open a password-protected document as I described previously, but there is no means for Keynote to do so without your manually entering the password for that document whose password was not stored in Keychain. You read too much into that quoted context from that What's new in Keynote for Mac content.

Jun 24, 2021 9:33 AM in response to KingPeter223

I am in need of the same. I have hundreds of iWork files with multiple passwords that can be used to open the files. Being able to script in the password attempts would be a huge time saver.


But since it's not possible, I got to waste an entire day manually attempting to open the files and remove passwords. Something that should have taken less than 5 minutes (as with MS Office files) took multiple hours.

Jun 24, 2021 11:10 AM in response to SGIII

I understand where you are coming from, but load of other tools allow command line options to open a password protected file, compression tools, microsoft office.. with your logic, turning on a computer could do harm so it would be best to not turn on the computer.


Believe me, I understand what you are saying. But the release notes say:

Keynote changelog:

  • Ability to use AppleScript to change the presentation password or open password-protected presentations

Which at face value is not true. It cannot open password protected files via apple script.

Alternative point of view, it was always possible, you just have to manually enter the password.


I have no desire to argue with you or go way off topic on semantics.


Thank you and good day sir.

Jun 24, 2021 9:35 PM in response to BMayhem

You can give feedback to Apple via Keynote > Provide Keynote Feedback in your menu. Perhaps they could have tweaked the wording of the release notes to prevent misunderstandings.


To me, though, the behavior is consistent with the wording. As in my example above, it is indeed now possible open a password-protected document with AppleScript, remove the password and save it again, without entirely opening up documents to automated hacking. For me that emphasis on security (requiring user input at a critical point) is a good thing!


SG

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.

how to open a password protected file from Applescript?

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