Adobe X OCR and Hazel

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Adobe X OCR and Hazel Mon Jul 08, 2013 2:38 pm • by tgwright
I am using the scripts from here. http://www.takecontrolbooks.com/news/up ... dfpen#prox
I put it in the correct folder and then enabled folder actions on the folder that I want Hazel to monitor and run the script in.
When I try and run the rule, I get this error.

2013-07-08 14:35:41.378 hazelworker[12763] Statement_Jun 2013 (1).pdf: Rule OCR PDF's matched.
2013-07-08 14:35:41.748 hazelworker[12763] [Error] AppleScript failed: Error executing AppleScript /Users/tgwright/.Trash/OCR This (Acrobat).scpt on file /Users/tgwright/Google Drive/Financials/To Be Processed/Statement_Jun 2013 (1).pdf.
2013-07-08 14:35:41.748 hazelworker[12763] AppleScript error: {
OSAScriptErrorNumberKey = "-1708";

I found in the help file that I needed to add "on hazelMatchFile(theFile)" to the start of my script and "end hazelMatchFile".
This caused errors about expecting end and found on instead.

Here is an exact copy of the text of my script.


-- OCR This (Acrobat)
-- Script by Joe Kissell <jk@alt.cc>
-- "How to make your office paperless" http://www.macworld.com/article/159007/
-- "Take Control of Your Paperless Office" http://www.takecontrolbooks.com/paperless-office

on adding folder items to this_folder after receiving these_items
UIscript_check()
tell application "Finder" to set appName to name of application file id "com.adobe.Acrobat.Pro"
tell application "Finder" to set appVersion to version of application file id "com.adobe.Acrobat.Pro"
repeat with i from 1 to number of items in these_items
set this_item to item i of these_items
set the item_info to info for this_item
tell application appName
activate
open this_item
end tell
tell application "System Events"
tell application process "Acrobat"
if (15th character of appVersion is "X") then
-- Acrobat Pro X
tell application "Adobe Acrobat Pro" to activate
if not (exists (menu item "OCR This" of menu 1 of menu item "Action Wizard" of the menu "File" of menu bar 1)) then
my setUpAction()
end if
my runOCRX()
else
if "Standard" is in appName then
-- Acrobat 7.0 Standard
click the menu item "Start..." of menu 1 of menu item "Recognize Text Using OCR" of the menu "Document" of menu bar 1
else
-- Acrobat Pro 7, 8, or 9
click the menu item "Recognize Text Using OCR..." of menu 1 of menu item "OCR Text Recognition" of the menu "Document" of menu bar 1
end if
try
click radio button "All pages" of group 1 of group 2 of group 1 of window "Recognize Text"
end try
click button "OK" of window "Recognize Text"
tell application appName
activate
save the front document
close the front document
end tell
end if
end tell
end tell
end repeat
end adding folder items to

on setUpAction()
tell current application
activate
set the dialog_message to "You do not currently have an “OCR This” Action configured. Click OK to set one up automatically and then run it to perform OCR on this document. You'll only need to perform this extra step once." & return & return & ¬
"Consult the documentation that came with this script for instructions about modifying the Action's behavior."
display dialog dialog_message
end tell
tell application "System Events"
tell application process "Acrobat"
tell application "Adobe Acrobat Pro" to activate
click the menu item "Create New Action" of menu 1 of menu item "Action Wizard" of the menu "File" of menu bar 1
delay 0.4
key code 125 -- Down - Move to Content
key code 125 -- Down - Move to Forms
key code 125 -- Down - Move to Recognize Text
key code 124 -- Right - Expand Recognize Text
delay 0.4
key code 125 -- Down - Move to Recognize Text (using OCR)
keystroke return -- add Recognize Text (using OCR) to Steps
delay 0.3
keystroke tab -- Move to Start with pop-up menu
keystroke tab -- Move to Steps
keystroke tab -- Move to Options
keystroke tab -- Move to Prompt User
keystroke tab -- Move to Add Instruction Step
keystroke tab -- Move to Save to pop-up menu
keystroke tab -- Move to Options
keystroke tab -- Move to Overwrite checkbox
keystroke tab -- Move to Save button
keystroke return -- Click Save button
keystroke "OCR This" -- type name
keystroke return -- Click Save button
end tell
end tell
end setUpAction

on runOCRX()
tell application "System Events"
tell application process "Acrobat"
tell application "Adobe Acrobat Pro" to activate
click the menu item "OCR This" of menu 1 of menu item "Action Wizard" of the menu "File" of menu bar 1
repeat until exists (window "Action: OCR This")
end repeat
click button "Next" of window "Action: OCR This"
repeat until exists (window "OCR This")
end repeat
click button "Close" of window "OCR This"
end tell
end tell
end runOCRX

on UIscript_check()
tell application "System Events"
set UI_enabled to UI elements enabled
end tell
if UI_enabled is false then
tell application "System Preferences"
activate
set current pane to pane "com.apple.preference.universalaccess"
set the dialog_message to "This script uses the GUI Scripting feature of Mac OS X, which is currently disabled." & return & return & ¬
"You can activate GUI Scripting by selecting the checkbox “Enable access for assistive devices” at the bottom of the Universal Access preference pane."
display dialog dialog_message buttons {"Cancel"} default button 1 with icon 1
end tell
end if
end UIscript_check

-- key code 123 -- Left
-- key code 124 -- Right
-- key code 125 -- Down
-- key code 126 -- Up
tgwright
 
Posts: 1
Joined: Mon Jul 08, 2013 2:32 pm

Re: Adobe X OCR and Hazel Mon Jul 08, 2013 3:58 pm • by a_freyer
First of all, this script is terrible. There is no reason to use keystrokes to select menu items, especially when Acrobat has an AppleScript dictionary.

Second, you cannot use functions within an AppleScript within Hazel. You'll notice that this script posted does have several internal functions.

I do not have Acrobat Pro to write a script for you, but I suggest trying to write a completely different script, or searching the forums for an OCR.
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado


Return to Support