On macOS Sonoma (14.7.4) or Sequoia (currently 15.3.2), the Preview application allows one to open a scanned PDF, choose Export…, and on that export panel, select Embed text. Saving the PDF performs OCR on the content allowing text selection and search.
Although documented in the Swift version of Apple’s PDFKit PDFDocument’s Write Operations PDFDocumentWriteOption as saveTextFromOCROption, it is omitted from the Objective-C counterpart docs. It still works in ASOC though.
use AppleScript version "2.4" -- Yosemite (10.10) or later
use framework "Foundation"
use framework "PDFKit"
use scripting additions
property ca : current application
property SUFFIX : "_withOCR"
-- select a PDF that you know has scanned text that has not been OCR'd
set thisPDF to POSIX path of (choose file of type "PDF") as text
set ext to (ca's NSString's stringWithString:thisPDF)'s pathExtension()
set outPDF to (ca's NSString's stringWithString:thisPDF)'s stringByDeletingPathExtension()
set outPDF to outPDF's stringByAppendingString:SUFFIX
set outPDF to outPDF's stringByAppendingPathExtension:ext
set optDict to ca's NSDictionary's dictionaryWithObject:(ca's PDFDocumentWriteOption's saveTextFromOCROption) forKey:(ca's PDFDocumentWriteOption)
set pdf to ca's PDFDocument's alloc()'s initWithURL:(ca's NSURL's fileURLWithPath:thisPDF)
-- write outPDF as an OCR'd PDF
pdf's writeToFile:outPDF withOptions:optDict
return