r/applescript • u/Gqsmoothster • May 27 '24
Scan to folder then OCR then Apple Notes
I found this awesome script:
https://github.com/altercation/apple-notes-inbox
on processFile(fileToProcess)
set theFile to fileToProcess as text
tell application "Finder" to set noteName to name of file theFile
set timeStamp to short date string of (current date) as string
set noteBody to "<body><h1>" & notePrefix & noteName & "</h1><p>Imported on: " & timeStamp & "</p></body>"
tell application "Notes"
if not (exists folder notesFolder) then
make new folder with properties {name:notesFolder}
end if
set newNote to make note at folder notesFolder with properties {body:noteBody}
make new attachment at end of attachments of newNote with data (file theFile)(truncated for the purposes of this post)
What I'd like is to insert a subroutine to send the PDF to an app called PDFScanner to do OCR on it before import to Notes. I reviewed the very sparse documentation for PDFScanner here
https://www.pdfscannerapp.com/applescript/
So I think my script needs to look like this:
on processFile(fileToProcess)
set theFile to fileToProcess as text
tell application "PDFScanner"
OCR theFile to theFile
end tell
tell application "Finder" to set noteName to name of file theFile
set timeStamp to short date string of (current date) as string
set noteBody to "<body><h1>" & notePrefix & noteName & "</h1><p>Imported on: " & timeStamp & "</p></body>"
tell application "Notes"
if not (exists folder notesFolder) then
make new folder with properties {name:notesFolder}
end if
set newNote to make note at folder notesFolder with properties {body:noteBody}
make new attachment at end of attachments of newNote with data (file theFile)But I do not know much about Apple Script so am looking for help with adjusting this script to suit my taste.
4
Upvotes
1
u/joelesler May 28 '24
I had a script running like this for years. Because of some bug in Notes, pdfs will get attached twice this way, Notes can’t handle it and will crash.
Doesn’t solve your problem, but I would suggest attaching files to Notes with a shortcut instead. Works and is more reliable.
1
u/GrilledBurritos May 30 '24
Hi, I don't know much about AppleScript or much coding at all. I was looking for something to be able to take my notes I take on iPad and automatically run it through OCR and create a new file with the OCR Text and the image to reference below. And also allow the notes to be editable and the OCR text file to be update. Does this fit that use function if the notes are saved as a PDF? Sorry about the illiteracy, thank you!
1
u/copperdomebodha May 30 '24
You can do OCR on PDFs directly without an application. I’ll pull the method and edit this post to add it.