Skip to content

Instantly share code, notes, and snippets.

@lachok
Created May 3, 2014 21:17
Show Gist options
  • Save lachok/5b401268c82b7f4b4a55 to your computer and use it in GitHub Desktop.
Save lachok/5b401268c82b7f4b4a55 to your computer and use it in GitHub Desktop.
AppleScript folder action and script application to OCR pdf files with PDFpen
--
-- OCR selected documents to a folder
--
on run
try
set input_items to choose file of type "com.adobe.pdf" with prompt "Choose input files:" with multiple selections allowed
set output_folder to choose folder with prompt "Choose output folder:"
tell application "Finder" to set output_folder_path to output_folder as text
doocr of input_items into output_folder_path
on error errText
display dialog "OCRMe Error: " & errText
end try
end run
--
-- OCR all documents added to a folder
--
on adding folder items to this_folder after receiving added_items
try
tell application "Finder" to set this_folder_path to this_folder as text
doocr of added_items into this_folder_path & "OCRed:"
on error errText
display dialog "OCRMe Error: " & errText
end try
end adding folder items to
on doocr of input_files into output_folder
set appName to my getAppName()
repeat with i from 1 to number of items in input_files
set this_item to item i of input_files
tell application "Finder" to set fileName to name of this_item
tell application appName
activate
using terms from application "PDFpen"
open this_item
set theDoc to document 1
if needs ocr of theDoc then
ocr theDoc
repeat while performing ocr of theDoc
end repeat
end if
close theDoc saving in file (output_folder & fileName)
end using terms from
end tell
end repeat
end doocr
on getAppName()
tell application "Finder"
try
try
set appName to name of application file id "com.smileonmymac.PDFpen"
on error
set appName to name of application file id "com.smileonmymac.PDFpenPro"
end try
on error
set appName to name of application file id "com.smileonmymac.PDFPen.MacAppStore"
end try
end tell
return appName as string
end getAppName
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment