FasdUAS 1.101.10 k l  NOTE: This script was written for Snow Leopard. It may work on Leopard, but I never tried it. This is a folder listener script that will act as a queue, receiving PDF files from the ScanSnap scanner and feeding them, one by one, to the Abbyy FineReader OCR software. This allows you to keep scanning while the OCR job runs in the background on all of the unprocessed files. Why do we want to do this? The ScanSnap Manager software does not support this by default, so when you scan in a file, it sends it to FineReader for OCR. You then must wait until FineReader finishes its work before scanning in another document. This script allows you to keep scanning without waiting for OCR. Installation: o Copy this script to: /Library/Scripts/Folder Action Scripts You may have to create the "Folder Action Scripts" folder. o Open a Finder window and navigate to the parent folder of the scanned documents folder. o Right click (control-click) the scanned documents folder and choose: Folder Actions Setup... o At this point if folder actions are not enabled, you will likely have to enable them and add the script manually. - check "Enable Folder Actions" - Use the "+" buttons on the left and right sides to add the scan folder and then this script. o Otherwise, a list of scripts will come up. Choose this script from the "Choose a Script to Attach" dialog. o Close all windows. Copyright (C) 2010 Tad Harrison   T NOTE: This script was written for Snow Leopard. It may work on Leopard, but I never tried it. This is a folder listener script that will act as a queue, receiving PDF files from the ScanSnap scanner and feeding them, one by one, to the Abbyy FineReader OCR software. This allows you to keep scanning while the OCR job runs in the background on all of the unprocessed files. Why do we want to do this? The ScanSnap Manager software does not support this by default, so when you scan in a file, it sends it to FineReader for OCR. You then must wait until FineReader finishes its work before scanning in another document. This script allows you to keep scanning without waiting for OCR. Installation: o Copy this script to: <home>/Library/Scripts/Folder Action Scripts You may have to create the "Folder Action Scripts" folder. o Open a Finder window and navigate to the parent folder of the scanned documents folder. o Right click (control-click) the scanned documents folder and choose: Folder Actions Setup... o At this point if folder actions are not enabled, you will likely have to enable them and add the script manually. - check "Enable Folder Actions" - Use the "+" buttons on the left and right sides to add the scan folder and then this script. o Otherwise, a list of scripts will come up. Choose this script from the "Choose a Script to Attach" dialog. o Close all windows. Copyright (C) 2010 Tad Harrison  j 0 ocrfilesuffix ocrFileSuffix m  8 processed by FineReader.pdf  j (0ocrapplicationnameocrApplicationName m,Scan to Searchable PDF j ,0ocrapplicationwindowocrApplicationWindow m.Converting the document j  "0ocrlockfilenameocrLockFileName m OCR in Progress i  ! I"# .facofgetnullalis "o 0 this_folder#$  flst $o 0 added_items !k%%&' &r() (b*+ *l , ,n -. -1  psxp .l/ /I01 .earsffdralis afdr 0m  afdmdesk12  rtyp 2m  ctxt +o  "0ocrlockfilenameocrLockFileName )o 0 lockfilepath lockFilePath'34 3Q567 5k889: 9I; 0logeventlogEvent;< <m==>>F=== Run OCR on New Folder Items ===:?@ ?lAB A1+ Test for lockfile; exit if lockfile existsBCCV Test for lockfile; exit if lockfile exists@DE DO+FG Fr *HI HI (J .coredoexboolobj J4 $K  file Ko"# 0 lockfilepath lockFilePath Io 0lockfileexistslockFileExists GmLLsevsalis Macintosh HDH+System Events.app%p7 CoreServices8'7 :Macintosh HD:System:Library:CoreServices:System Events.app$System Events.app Macintosh HD-System/Library/CoreServices/System Events.app/EMN MZ,EOPQ Oo,- 0lockfileexistslockFileExists Pk09RRST SI06U 0logeventlogEventUV Vm12WWXX@Other script running. Exiting...TY YL79 QI<EZ .sysoexecTEXTTEXT Zb<A[\ [b<?]^ ]m<=__`` /usr/bin/touch " ^o=> 0 lockfilepath lockFilePath \m?@aabb"Ncd clFFef e Main loopfgg Main loopdhi hrFIjk jmFG  boovtrue ko 0 moreworktodo moreWorkToDoilm lVJqno nkPlppqr qrPXst sIPVu 0 getnextfile getNextFileuv voQR 0 this_folder to 0afileaFilerw wZYlxyz xHY]{ {=Y\|} |oYZ 0afileaFile }mZ[~~ yI`f 0ocrfileocrFile oab 0afileaFile zril mij  boovfals o 0 moreworktodo moreWorkToDo ooNO 0 moreworktodo moreWorkToDom Irz 0logeventlogEvent msvNo more work. I{ 0exitappexitApp o| (0ocrapplicationnameocrApplicationName 6R .ascrerr ******** o 0errorstrerrorStr  errn o 0errnumerrNum 7k I .sysodlogaskrTEXT b b b m Error o 0errnumerrNum m( while running OCR: o 0errorstrerrorStr r m  boovfals n o 0 isrunning isRunning f4 l 3- Get rid of the lockfile, ignoring any errorsZ Get rid of the lockfile, ignoring any errors Q I .sysoexecTEXTTEXT b b m/bin/rm " o 0 lockfilepath lockFilePath m" R .ascrerr ******** l pj Name: ocrFile Description: Runs OCR on the next un-OCR'd file Parameters: aFile - the file to be OCR'd  Name: ocrFile Description: Runs OCR on the next un-OCR'd file Parameters: aFile - the file to be OCR'd  i I 0ocrfileocrFile o 0afileaFile k] r n 1  psxp o 0afileaFile o 0 posixfilepath posixFilePath r I *0getposixocrfilepathgetPosixOcrFilePath o 0 posixfilepath posixFilePath o $0posixocrfilepathposixOcrFilePath I 0logeventlogEvent b m OCR: o 0 posixfilepath posixFilePath O) I#( .aevtodocnullalis o#$ 0afileaFile 4  capp o (0ocrapplicationnameocrApplicationName l** l** B< Now sit in a loop checking once per second for the OCR filex Now sit in a loop checking once per second for the OCR file l** ! Give up after five minutes6 Give up after five minutes l** t*] k,\ r,/ m,-  boovfals o 0 ocrfileexists ocrFileExists W0\ k6W r6> I6< "0posixfileexistsposixFileExists o78 $0posixocrfilepathposixOcrFilePath o 0 ocrfileexists ocrFileExists Z?W~ o?@} }0 ocrfileexists ocrFileExists kCO ICI|{ |0logeventlogEventz mDE&OCR file generated.z{ lJJyy >8 Wait 5 even if the file was found, to let things settle  p Wait 5 even if the file was found, to let things settle x  IJOw v w.sysodelanullnmbr  mJKuuvx~ kRW     lRRtt *$ Wait a second before checking againH Wait a second before checking agains IRWrq r.sysodelanullnmbr mRSppqs o45o o0 ocrfileexists ocrFileExists m*+nn, lmm  Name: appIsRunning Description: Determines if a particular application is running. Parameters: appName - the name of the application to be tested Returns: True if the application is running; otherwise False  Name: appIsRunning Description: Determines if a particular application is running. Parameters: appName - the name of the application to be tested Returns: True if the application is running; otherwise False  i Ilk l0 appisrunning appIsRunningj oi i0appnameappNamejk O  E !" !l #hg #n $% $1 f f pnam %2e e prcshg "o d d0appnameappName  m&&sevsalis Macintosh HDH+System Events.app%p7 CoreServices8'7 :Macintosh HD:System:Library:CoreServices:System Events.app$System Events.app Macintosh HD-System/Library/CoreServices/System Events.app/'( 'lc)*c ) Name: posixFileExists Description: Determines if a particular file exists. Parameters: posixFilePath - the POSIX path to the file Returns: True if the file exists; otherwise False *++l Name: posixFileExists Description: Determines if a particular file exists. Parameters: posixFilePath - the POSIX path to the file Returns: True if the file exists; otherwise False (,- ,i./ .Ib0a b"0posixfileexistsposixFileExists01` 1o_ _0 posixfilepath posixFilePath`a /O 23 2I ^4] ^.coredoexboolobj 44\5 \ file 5o[ [0 posixfilepath posixFilePath] 3m66sevsalis Macintosh HDH+System Events.app%p7 CoreServices8'7 :Macintosh HD:System:Library:CoreServices:System Events.app$System Events.app Macintosh HD-System/Library/CoreServices/System Events.app/-78 7lZ9:Z 9xr Name: exitApp Description: Exits the specified app if it is running. Parameters: appName - the application name :;; Name: exitApp Description: Exits the specified app if it is running. Parameters: appName - the application name 8<= <i>? >IY@X Y0exitappexitApp@AW AoV V0appnameappNameWX ?ZBCUT BISDR S0 appisrunning appIsRunningDEQ EoP P0appnameappNameQR CO FG FIONM O.aevtquitnullnullNM G4 LH L capp Ho K K0appnameappNameUT=IJ IlJKLJ K Name: getPosixOcrFilePath Description: Gets the OCR output filename for a given input filename. Parameters: posixFilePath - the full path to the source file Return: the POSIX path of the OCR output file LMM Name: getPosixOcrFilePath Description: Gets the OCR output filename for a given input filename. Parameters: posixFilePath - the full path to the source file Return: the POSIX path of the OCR output file JNO Ni #PQ PIIRH I*0getposixocrfilepathgetPosixOcrFilePathRSG SoF F0 posixfilepath posixFilePathGH QkTTUV Ur WX WI EYD E.sysoexecTEXTTEXT YbZ[ Zb\] \l ^CB ^m__``filename=CB ]nab a1A A strq bo@ @0 posixfilepath posixFilePath [mccdd,; echo ${filename%\.*}D Xo? ?0 posixbasename posixBaseNameVef ergh gbij io> >0 posixbasename posixBaseName jo= =0 ocrfilesuffix ocrFileSuffix ho< <$0posixocrfilepathposixOcrFilePathfk; kLl lo: :$0posixocrfilepathposixOcrFilePath;Omn ml9op9 oe_ Name: getNextFile Description: Finds the next unprocessed ScanSnap PDF Return: the file or "" pqq Name: getNextFile Description: Finds the next unprocessed ScanSnap PDF Return: the file or "" nrs ri$'tu tI8v7 80 getnextfile getNextFilevw6 wo5 50afolderaFolder67 ukxxyz yI4{3 40logeventlogEvent{|2 |m}}~~(Getting next file...23z r I1 1.earslfdrutxt@file l 0/ o. .0afolderaFolder0/-, - lfiv m + + boovfals, o* * 0masterfilelistmasterFileList r n 1) ) psxp o( (0afolderaFolder o' '0 posixpath posixPath Y&% k% r%+ n%) 4&)$ $ cobj o'(# #0i o%&" " 0masterfilelistmasterFileList o! !0filenamefileName r,1 b,/ o,- 0 posixpath posixPath o-. 0filenamefileName o 0 posixfilepath posixFilePath I27 .ascrcmnt******** o23 0 posixfilepath posixFilePath l88 l88 5/ Construct a FineReader file name from our file^ Construct a FineReader file name from our file l88 r8@ I8> *0getposixocrfilepathgetPosixOcrFilePath o9: 0 posixfilepath posixFilePath o $0posixocrfilepathposixOcrFilePath lAA    lAA  71 See if the FineReader file we constructed existsb See if the FineReader file we constructed exists lAA    rAI IAG "0posixfileexistsposixFileExists oBC $0posixocrfilepathposixOcrFilePath o 0 ocrfileexists ocrFileExists OJZ rNY INW $0getspotlightinfogetSpotlightInfo  for mPQkMDItemCreator  from oRS 0 posixfilepath posixFilePath o 0 filecreator fileCreator fJK I[b .ascrcmnt******** l[^ b[^ m[\Creator: o\] 0 filecreator fileCreator Zc Fcq Hce ocd 0 ocrfileexists ocrFileExists =hm ohi 0 filecreator fileCreator mil ScanSnap Manager Lt| 4t{  psxf oxy 0 posixfilepath posixFilePath &0i m I  .corecnte******** o 0masterfilelistmasterFileList% L ms l  Name: getSpotlightInfo Description: Gets a named attribute from metadata for a specific file. Parameters: for myattribute - the name of the attribute from myfile - the name of the file Returns: the attribute value or "" if none found  Name: getSpotlightInfo Description: Gets a named attribute from metadata for a specific file. Parameters: for myattribute - the name of the attribute from myfile - the name of the file Returns: the attribute value or "" if none found  i(+ I $0getspotlightinfogetSpotlightInfo  for o 0 myattribute  from o 0myfile kz Qw kj r m o (0this_kmditemresultthis_kMDItemResult l Oj k i r  c    o 0myfile  m  TEXT  o 0 this_item   r n 1  psxp o 0 this_item o 0 this_item  r o 0 myattribute o 0 this_kmditem this_kMDItem r, n* 2(*  cwor l( I( .sysoexecTEXTTEXT b$ b  !  b"# "m$$%%(/usr/bin/mdls -name #o 0 this_kmditem this_kMDItem !m&&''. -raw -nullMarker None n #() (1!#  strq )o ! 0 this_item o 0 theresult theResult*+ *I-6, .ascrcmnt******** ,c-2-. -b-0/0 /m-.1122Result: 0o./ 0 theresult theResult .m01  TEXT+3 3Y7i456 4kFd7789 8rFP:; :cFN<= <bFL>? >oFG (0this_kmditemresultthis_kMDItemResult ?nGK@A @4HKB  cobj BoIJ 0j AoGH 0 theresult theResult =mLM  TEXT ;o (0this_kmditemresultthis_kMDItemResult9C CZQdDE DAQXFG FoQR 0j GnRWHI HmUW  nmbr InRUJK J2SU  cobj KoRS 0 theresult theResult Er[`LM Lb[^NO No[\ (0this_kmditemresultthis_kMDItemResult Om\]PPQQ Mo (0this_kmditemresultthis_kMDItemResult 0j 5m:; 6n;ARS Rm>@  nmbr Sn;>TU T2<>  cobj Uo;< 0 theresult theResult mVVMACSalisr Macintosh HDH+ Finder.apptƘ CoreServicesƘK 3Macintosh HD:System:Library:CoreServices:Finder.app Finder.app Macintosh HD&System/Library/CoreServices/Finder.app/ R .ascrerr ******** rrwWX WmruYYZZ Xo (0this_kmditemresultthis_kMDItemResult[ [Lxz\ \oxy (0this_kmditemresultthis_kMDItemResult]^ ]l_` _|v Name: logEvent Description: Write an event to an event log Parameters: themessage - the message to write to the log `aa Name: logEvent Description: Write an event to an event log Parameters: themessage - the message to write to the log ^bc bi,/de dIf 0logeventlogEventfg go 0 themessage ekhhij ir kl kb mn mb op ol q qlr rIst .sysoexecTEXTTEXT sl u umvvww4date +'%Y-%m-%d %H:%M:%S'tx  rtyp xm  TEXT pmyyzz no 0 themessage lo 0thelinetheLinej{ {I| .sysoexecTEXTTEXT |b}~ }b m echo o 0thelinetheLine ~l  mR >> ~/Library/Logs/AppleScript-events.logc l  0 ocrfilesuffix ocrFileSuffix (0ocrapplicationnameocrApplicationName ,0ocrapplicationwindowocrApplicationWindow "0ocrlockfilenameocrLockFileName .facofgetnullalis 0ocrfileocrFile 0 appisrunning appIsRunning "0posixfileexistsposixFileExists 0exitappexitApp *0getposixocrfilepathgetPosixOcrFilePath 0 getnextfile getNextFile $0getspotlightinfogetSpotlightInfo 0logeventlogEvent! .facofgetnullalis 0 this_folder~}  flst ~0 added_items}|{zyxwvu |0 this_folder {0 added_items z0 lockfilepath lockFilePath y 0lockfileexistslockFileExists x0 moreworktodo moreWorkToDo w0afileaFile v0errorstrerrorStr u0errnumerrNumtsrqp=oLnmW_alk~jihgfed t afdmdesk s rtyp r ctxt q.earsffdralis afdr p psxp o0logeventlogEvent n file m.coredoexboolobj l.sysoexecTEXTTEXT k0 getnextfile getNextFile j0ocrfileocrFile i0exitappexitApp h0errorstrerrorStrcba c errn b0errnumerrNuma g.sysodlogaskrTEXT f0 isrunning isRunningedl ,b%EOu*k+O */j EUO*k+OhY %%j OeEO&h*k+EO  *k+YfE[OYO*ak+O*bk+WXa%a%%j Of)a,FOa%a%j WXh`_^] `0ocrfileocrFile_\\[ [0afileaFile^ZYXW Z0afileaFile Y0 posixfilepath posixFilePath X$0posixocrfilepathposixOcrFilePath W0 ocrfileexists ocrFileExists VUTSRQPON V psxp U*0getposixocrfilepathgetPosixOcrFilePath T0logeventlogEvent S capp R.aevtodocnullalisQ, P"0posixfileexistsposixFileExistsO N.sysodelanullnmbr]^,EO*k+EO*%k+O*b/j UOnfEO+h*k+EO*k+Oj Ykj [OYoMLKJ M0 appisrunning appIsRunningLIIH H0appnameappNameKG G0appnameappName&FE F prcs E pnamJ  *-,UD/CBA D"0posixfileexistsposixFileExistsC@@? ?0 posixfilepath posixFilePathB> >0 posixfilepath posixFilePath6=< = file <.coredoexboolobj A */j U;?:98 ;0exitappexitApp:776 60appnameappName95 50appnameappName432 40 appisrunning appIsRunning 3 capp 2.aevtquitnullnull8*k+*/*j UYh1Q0/. 1*0getposixocrfilepathgetPosixOcrFilePath0--, ,0 posixfilepath posixFilePath/+*) +0 posixfilepath posixFilePath *0 posixbasename posixBaseName )$0posixocrfilepathposixOcrFilePath_(c' ( strq '.sysoexecTEXTTEXT.,%%j EOb%EO&u%$# &0 getnextfile getNextFile%""! !0afolderaFolder$  0afolderaFolder  0masterfilelistmasterFileList 0 posixpath posixPath 0i 0filenamefileName 0 posixfilepath posixFilePath $0posixocrfilepathposixOcrFilePath 0 ocrfileexists ocrFileExists 0 filecreator fileCreator}   0logeventlogEvent  lfiv .earslfdrutxt@file  psxp .corecnte********  cobj .ascrcmnt******** *0getposixocrfilepathgetPosixOcrFilePath "0posixfileexistsposixFileExists  for  from  $0getspotlightinfogetSpotlightInfo  bool  psxf#*k+Ofl EO,EOmkj kh/EO%EOj O*k+EO*k+ EO) * EUO%j O aa& *a/EYh[OYOa $0getspotlightinfogetSpotlightInfo  for 0 myattribute  from  0myfile 0 myattribute 0myfile (0this_kmditemresultthis_kMDItemResult 0 this_item 0 this_kmditem this_kMDItem 0 theresult theResult 0jV$&1PY  TEXT  psxp  strq .sysoexecTEXTTEXT  cwor .ascrcmnt********  cobj  nmbr{lEO`&EO,EOEO%%,%j -EO%&j O1k-,Ekh/%&EO-, %EYh[OYUW XaEOe 0logeventlogEvent 0 themessage 0 themessage 0thelinetheLinevy  rtyp  TEXT .sysoexecTEXTTEXTl %%EO%%j ascr ޭ