Friday, October 22, 2021

#1 2021-06-06 06:02:57 am

One208
Member
Registered: 2021-03-15
Posts: 32

wait while file is written

Hi
I want to wait for file to be processed by ABBYY FineReader for ScanSnap before it quits, its a issue for large file

Here is my attempt

Applescript:


tell application "Finder"
   set theFile to selection
   set fileSizeO to size of (info for theFile)
end tell
tell application "ABBYY FineReader for ScanSnap"
   recognize theFile and export to theFile as pdf with silent mode
end tell
-- I thought the size wud change after processing, so reCheck the size ? is it appropriate
tell application "Finder" to set fileSize to size of (info for theFile)
repeat until fileSize ≥ fileSizeO
   delay 1
end repeat

tell application "ABBYY FineReader for ScanSnap" to quit

Off course this does not work

ABBYY FineReader for ScanSnap dictionary :
application n [inh. application; see also Standard Suite] : The application's top-level scripting object.
properties
busy (boolean, r/o) : Is ABBYY FineReader for ScanSnap application busy?
responds to
show preferences, recognize.


Cud this Busy be used to determine if file is processed


Cheers

Offline

 

#2 2021-06-06 07:09:41 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 2091

Re: wait while file is written

Probably it is difficult to find an experienced scriptwriter who has this application and already scripted it. Therefore, I will try to help by working blindly. I cannot help with the busy property due to the lack of a dictionary. But I will try to fix the parts of the script that are familiar.

So, until you get a better solution, test this:

Applescript:


-- Get source file size, make new empty destination file (to avoid security problems)
tell application "Finder"
   set sourceFile to item 1 of (get selection) as alias
   set theName to name of sourceFile
   set fileSizeO to size of (info for sourceFile)
   set destinationFile to (make new file at desktop with properties {name:theName}) as alias
end tell

-- open source file, scan document and export it
tell application "ABBYY FineReader for ScanSnap"
   set aDocument to open sourceFile
recognize aDocument and export to file (destinationFile as text) as pdf with silent mode
end tell

-- wait until exporting teminates
repeat until (size of (info for destinationFile)) ≥ fileSizeO
delay 1
end repeat

-- close all
tell application "ABBYY FineReader for ScanSnap"
close documents saving no
quit
end tell

Last edited by KniazidisR (2021-06-06 07:15:46 am)


Model: MacBook Pro
OS X: Catalina 10.15.7
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

#3 2021-06-06 10:42:28 am

Mockman
Member
From:: Toronto
Registered: 2020-05-27
Posts: 134

Re: wait while file is written

There is a post which includes a script provided by Abbyy's support that uses 'busy' to determine whether the script should go into a holding pattern. You can read the whole thing here but below are the specific handlers used in it:

https://macscripter.net/viewtopic.php?p … 59#p178759

Applescript:

on WaitWhileBusy()
repeat while IsMainApplicationBusy()
end repeat
end WaitWhileBusy

on IsMainApplicationBusy()
tell application "FineReader OCR Pro"
set resultBoolean to is busy
end tell
return resultBoolean
end IsMainApplicationBusy

In essence, the first handler is called when you want to check busy. It then calls the second handler which returns true until it returns false, which lets the first handler finish and the script proceed.

Note that the name is different than the OP's. I use 'FineReader' myself. I don't know how similar the scripting functionality would be between the three versions. On my system however, 'busy' will return true while the app is inhaling a large document and then false when it's complete, so if the command is available in your version, it should work.

FWIW, I don't think that the size trick would work reliably. If the file increased in size incrementally, then even a 1 byte change would allow the script to proceed.

Does your version's dictionary include 'get document progress'?

Last edited by Mockman (2021-06-06 10:52:33 am)


Filed under: Abbyy Finereader

Offline

 

#4 2021-06-06 12:04:38 pm

Mockman
Member
From:: Toronto
Registered: 2020-05-27
Posts: 134

Re: wait while file is written

Here is something to try. As mentioned above, my version is not the same as yours. Mine uses different syntax for 'export'. I include what might work for you in comments.

If you get an error around `is finereader controller active` then your version presumably doesn't support that. Strip the `if…then` block and consider placing `WaitWhileBusy()` there instead (if you need a delay before the export begins). It might be better to move `WaitWhileBusy()` to immediately above the `quit` command.

Applescript:

tell application "Finder"
   set tfa to selection as alias
   set tf to POSIX path of (selection as alias)
   set tn to name of tfa
   set op to (path to desktop) & "op.pdf" as text
end tell

tell application "FineReader"
   activate
   if (is finereader controller active) is true then
       
       export to pdf op from file tf
       -- export to op as pdf with silent mode
       
       tell me to WaitWhileBusy()
       
   end if    
   quit
end tell

on WaitWhileBusy()
   repeat while IsMainApplicationBusy()
   end repeat
end WaitWhileBusy

on IsMainApplicationBusy()
   tell application "FineReader"
       set resultBoolean to is busy
   end tell
   return resultBoolean
end IsMainApplicationBusy

Offline

 

#5 2021-10-14 09:11:46 am

One208
Member
Registered: 2021-03-15
Posts: 32

Re: wait while file is written

Mockman wrote:

Does your version's dictionary include 'get document progress'?


Hi, Dictionary does not include 'get document progress'
Really does not have a lot in Dictionary (at least to me (newbie))

ABBYY FineReader for ScanSnap Suite    ABBYY FineReader for ScanSnap specific classes.
export format enum
    pdf : Searchable PDF Document.
    word document : Microsoft Word Document.
    excel spreadsheet : Microsoft Excel Workbook.
    power point presentation : Microsoft Power Point Presentation.
show preferences v : Shows ABBYY FineReader for ScanSnap preferences.
    show preferences
recognize v : Recongizes a document and exports it to the specified format.
    recognize file
       [and export to file] : Specified destination file.
       [as pdf/word document/more…] : Export format.
       [deprecated remove input files boolean] : Deprecated remove import files.
       [silent mode boolean] : Run application in silent mode.
application n [inh. application; see also Standard Suite] : The application's top-level scripting object.
    properties
    busy (boolean, r/o) : Is ABBYY FineReader for ScanSnap application busy?
    responds to
    show preferences, recognize.

Offline

 

#6 2021-10-14 09:15:29 am

One208
Member
Registered: 2021-03-15
Posts: 32

Re: wait while file is written

Hi Mockman

tried the waiting Handler →throws an error

tell application "Finder"
    get selection
end tell
tell application "ABBYY FineReader for ScanSnap"
    get busy
    recognize alias "Catalina:Users:one:Desktop:CCF26122017_40 2 4.pdf" and export to alias "Catalina:Users:one:Desktop:CCF26122017_40 2 4.pdf" as pdf with silent mode
    get busy
    get busy
   
   
Result:
error "ABBYY FineReader for ScanSnap got an error: Connection is invalid." number -609

Offline

 

#7 2021-10-14 10:07:37 am

One208
Member
Registered: 2021-03-15
Posts: 32

Re: wait while file is written

Hi KniazidisR
This seems to work smile

Applescript:

tell application "Finder"
set theFile to selection as alias
set fileSizeO to size of (info for theFile)
end tell
tell application "ABBYY FineReader for ScanSnap"
   recognize theFile and export to theFile as pdf with silent mode
repeat until (size of (info for theFile)) is not equal to fileSizeO
   delay 1
end repeat
quit
end tell

Offline

 

#8 2021-10-14 10:20:01 am

Mockman
Member
From:: Toronto
Registered: 2020-05-27
Posts: 134

Re: wait while file is written

I think it's partly related to your version. Did it come along with a scansnap scanner? If so, it looks like it has more limitations. I'm using FineReader Pro for Mac v12 and it has a decent dictionary (20+ commands).

What comes to mind is does your script always refer to finereader the same way? For example, in the two scripts I posted below, the app is not referred to as 'ABBYY FineReader for ScanSnap'. I think that the script may be trying to 'connect' to something finereader-related which doesn't exist on your system.

That said, it looks like 'busy' is available in your version. Where did you call the handler in your script?


Filed under: FineReader

Offline

 

#9 2021-10-14 11:27:43 am

One208
Member
Registered: 2021-03-15
Posts: 32

Re: wait while file is written

Hi Mockman
Thank you for your interest. Here is the script which I tried. It does OCR the document, but wud not close. As it throws error as documents before, it blocks the subsequent workflow.
Cheers

Applescript:

tell application "Finder" to set theFile to selection as alias

tell application "ABBYY FineReader for ScanSnap"
   my WaitWhileBusy() -- tried version where it called the handler here & without →same error
   recognize theFile and export to theFile as pdf with silent mode
   delay 1
   tell me to WaitWhileBusy(). -- If I dont call this handler here, Abbyy quits
   quit
end tell
on WaitWhileBusy()
   repeat while IsMainApplicationBusy()
   end repeat
end WaitWhileBusy

on IsMainApplicationBusy()
   tell application "ABBYY FineReader for ScanSnap"
       set resultBoolean to busy
   end tell
   return resultBoolean
end IsMainApplicationBusy

Last edited by One208 (2021-10-14 11:35:31 am)

Offline

 

#10 2021-10-15 09:41:41 am

Mockman
Member
From:: Toronto
Registered: 2020-05-27
Posts: 134

Re: wait while file is written

That's difficult for me to mimic exactly as the dictionary on my version is very different (doesn't have recognize, for example).

All I can suggest is grasping at straws… is there a 'close' command? Maybe try 'close document 1 without saving'. There should be some 'standard' commands (e.g. close, quit).

What happens if you 'delay 5' immediately prior to attempting to quit/close (if it helps then reduce until it stops helping).

Worst case scenario, send an email to Abbyy's tech support.

Offline

 

#11 2021-10-15 12:08:11 pm

One208
Member
Registered: 2021-03-15
Posts: 32

Re: wait while file is written

Thanks Mockman, Besides Abby scansnap suite I posted above, rest of standard suite is below, nothing else exists

Standard Suite    Common classes and commands for all applications.
quit v : Quit the application.
quit
application n [see also ABBYY FineReader for ScanSnap Suite] : The application's top-level scripting object.
properties
name (text, r/o) : The name of the application.
frontmost (boolean, r/o) : Is this the active application?
version (text, r/o) : The version number of the application.
responds to
quit.


Just wondering if cud be done with shell
something like

open -W -a 'ABBYY FineReader for ScanSnap' theFile -j -g


I think -w makes it wait till the application quits
I'll give this a try with a large file, usually 1-2 mb files are not an issue
Cheers

Offline

 

#12 2021-10-15 01:57:07 pm

Mockman
Member
From:: Toronto
Registered: 2020-05-27
Posts: 134

Re: wait while file is written

Well, it looks like you have to go with the 'quit' command.


It might be wise to use the path to the app in the shell command, e.g. 

open -W -a '/Applications/FineReader.app' /Users/username/Desktop/abc663366.png

Of course, you could put that in an applescript as well.

Offline

 

#13 2021-10-16 04:28:59 am

KniazidisR
Member
From:: Greece
Registered: 2019-03-03
Posts: 2091

Re: wait while file is written

First, find quoted form of  Posix path of ABBYY FineReader for ScanSnap.app
Then, put this quoted path in the Mockman's script instead of quoted form of posix path of ABBYY FineReader.app.

Applescript:


set quotedAppPosixPath to quoted form of (POSIX path of (path to application "ABBYY FineReader for ScanSnap"))
set quotedImagePosixPath to quoted form of (POSIX path of (choose file of type "public.image"))

do shell script "open -w -a " & quotedAppPosixPath & space & quotedImagePosixPath

NOTES: 1) can't test myself. 2) if this approach doesn't work, then you can always use do script of Terminal.app for scanning. Because checking busy status of Terminal window is easy.

Last edited by KniazidisR (2021-10-16 04:41:40 am)


Model: MacBook Pro
OS X: Catalina 10.15.7
Web Browser: Safari 14.1
Ram: 4 GB

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)