How to Bulk Password Protect a Large Number of PDF Files with PDFPen

I have PDFPen Pro if that matters.

Unfortunately, for regulatory reasons, I cannot use a password protected ZIP file to aggregate these files.

Possibly, an AppleScript? (I’m a newbie there) Keyboard Maestro? (same newbie status)

Thank you.

Unless PDFpenPro has that as a feature, I’d look for another tool, personally.

I have not tried either of these two, but based on what I found at GitHub, these would be the first two I’d look at for starters

1 Like

Here’s a solution using AppleScript and PDFpen. Just select all of the PDF files in Finder, then run the script in Script Editor.

use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

set pdfpen to path to application "PDFpen"
set suffix to "-protected.pdf" -- This will append "-protected" to the original file name.

tell application "Finder"
	set theResponse to display dialog "Enter Desired Password" default answer "" with hidden answer -- Prompt for a password.
	set thePassword to (text returned of theResponse)
	set selectedFiles to selection -- Get the files currently selected in Finder.
	open selectedFiles using pdfpen -- Open the files with PDFpen.
	delay 3
	tell application "PDFpen"
		repeat with theDocument in documents
			set documentPath to (path of theDocument) -- The full path to the file.
			set documentName to (name of theDocument) -- The file name with extension.
			set folderName to do shell script "dirname " & quoted form of POSIX path of documentPath -- Get the name of the containing folder.
			set fileNameNoExtension to do shell script "filename=" & quoted form of documentName & ";" & "echo ${filename%.*}" -- Remove the extension from the file name.
			set savePath to folderName & "/" & fileNameNoExtension & suffix -- Construct the path to the protected file, e.g., /path/to/myfile-protected.pdf
			save theDocument in POSIX file savePath password thePassword -- Save the file, protecting it with the provided password.
		end repeat
		quit saving no
	end tell
end tell
1 Like

Wow! Thank you very much. I had almost given up. Much obliged.

That’s very cool! Thanks for sharing it!

You’re welcome! I’m happy to help.

1 Like