I’m trying to set the following handler to use the VNRequestTextRecognitionLevelFast enumeration, and I can’t get the syntax correct. I’ve worked on this for an hour and thought I should ask for help.
The documentation is here. The handler is:
use framework "Foundation"
use framework "Vision"
use scripting additions
set theFile to POSIX path of (choose file)
set theText to getImageText(theFile)
on getImageText(theFile)
set theFile to current application's |NSURL|'s fileURLWithPath:theFile
set requestHandler to current application's VNImageRequestHandler's alloc()'s initWithURL:theFile options:(missing value)
set theRequest to current application's VNRecognizeTextRequest's alloc()'s init()
requestHandler's performRequests:(current application's NSArray's arrayWithObject:(theRequest)) |error|:(missing value)
set theResults to theRequest's results()
set theArray to current application's NSMutableArray's new()
repeat with anObservation in theResults
set theResult to ((anObservation's topCandidates:1)'s objectAtIndex:0)'s |string|()
(theArray's addObject:theResult)
end repeat
return (theArray's componentsJoinedByString:linefeed) as text
end getImageText