The following AppleScript will produce a dialog with a list of those PDFs found in the user's HOME directory that require a password to open. It ignores locked or simply encrypted PDFs, and those that are empty.
The key in this script is that a Password-protected PDF prevents one from accessing its PDF attributes and I use that as a trigger to add that non-zero PDF to the list of PDFs bearing passwords. Because AppleScript dialogs by default are not resizeable, I am using a tilde path on the file paths to shorten the strings.
Of the 1058 PDFs in my home directory, here is the example script output:
On my M4 Mac Mini Pro running Sequoia v15.1, this takes about 2 seconds.
Launch Apple's Script Editor and then copy/paste the following code in to it. Click the hammer button and then run.
(*
find_pdf_pass.applescript
Tested: macOS v15.1
Version: 1
Author: VikingOSX, 2024-11-10, Apple Support Communities, No warranty at all.
*)
use framework "Foundation"
use framework "PDFKit"
use AppleScript version "2.4" -- yosemite or later
use scripting additions
property ca : current application
set protectedPDF to ca's NSMutableArray's new()
set foundPDF to paragraphs of (do shell script "mdfind -onlyin $HOME 'kMDItemContentType == \"com.adobe.pdf\"'")
if (count of foundPDF) = 0 then return
repeat with aPDF in foundPDF
set pdf to (ca's PDFDocument's alloc()'s initWithURL:(ca's NSURL's fileURLWithPath:aPDF))
try
-- only fails for password protected PDF
pdf's documentAttributes
on error
set pdfSize to (do shell script "/usr/bin/stat -f '%z' " & aPDF's quoted form)
if pdfSize > 0 then
(protectedPDF's addObject:((ca's NSString's stringWithString:aPDF)'s stringByAbbreviatingWithTildeInPath))
end if
end try
end repeat
if (count of protectedPDF) = 0 then return
display dialog (protectedPDF's componentsJoinedByString:return) as text ¬
with title "Non-zero Password Protected PDFs"
return