Page 1 of 1

Paperless Scanning Script for CLSCAN.EXE

Posted: Fri Dec 22, 2023 9:20 am
by COBS Tech Support
This script requires Version 14, Build 1581 or higher.

Code: Select all

* Scan Script Support for CLScan
* https://www.terminalworks.com/command-line-scanning/downloads
* COBS, 18/12/23 (WN)

Declare nResult Type Number
Declare cBatch Type Character
Declare cPath Type Character
Declare cBatch Type Character
Declare cBatchScript Type Character
Declare nCount Type Number
Declare nTimeOut Type Number

cPath  := PathPersonal()
cBatch   := cPath + "Scan.bat"

* Wait 30 seconds for scan to be processed
* (may require adjustment)
nTimeOut := 30

If IsFile(cPath + cDocName)
   If .Not. EraseFile(cPath + cDocName)
      Echo("Could not erase temporary scan document: " + cPath + cDocName,, TRUE)
   Endif
Endif

cBatchScript := PathProgram() + 'clscan.exe /SetFileName "' + cPath + cDocName + '" /SetPageSize "A4" /SetColorType "GRAY"'

WriteTextFile(cBatch, cBatchScript)

EchoBoxOn("Requesting Scan", "Starting scan process...")

*nResult := Shell(cBatch)
nResult  := Shell(cBatch,,, 0)
nCount   := nTimeOut / 5

:Loop
   If WaitFile(cPath + cDocName, 5)
      Goto Done
   Endif

   nCount := nCount - 1
   EchoBox("Waiting for result... " + NTrim(nCount))
   
   If nCount <= 0
      nResult := 0
      Goto Done
   Endif

   Goto Loop

:Done

EchoBoxOff()

If nResult >= 0 .And. nResult <= 32
   Return FALSE
Endif

If IsFile(cPath + cDocName)
   Return cPath + cDocName
Endif

Return FALSE