Is there a way to add a comment on a file from occ ?
I’m trying to run OCR on my images (meme, screenshots, etc…) for easy search with comments.
I tried to find a plugin doing that directly, but none seems to exist or to be still under development. The Full text search - Files - Tesseract OCR is not tested over v27.
So I tried using Workflow OCR (using tesserect behind the scene) and trigger it, but it only transforms the images into a pdf and that’s it. I don’t want to have a pdf copy of my images, I only want to add the text as a comment (I don’t care about the format, position, etc…).
So I can use the Workflow Script to run an external shell-script to run tesseract and get text as stdout, but now I need a way to add the tesseract stdout as comment on the file.
Any way to do that from occ, or should I need to call the url via a custom curl command, or create a whole app (don’t really want to do that due to time constraints) ?
My setup:
Nextcloud version: 29.0.4
Operating system and version : Debian 12 BookWorm
Apache or nginx version : Caddy 2.6.2-5
PHP version: 8.2.20-1-deb12u1
Its not documented in the README (will try to rememeber to fix this) but its on the occ command files_scripts:run description). You can pass in file IDs as a command argument
occ files_scripts:run <script-id> -f $NC_FILEID
Which is then available in the script as a file input
Oh that’s nice, it would allow to skip the authentication part.
The downside is the learning curve to implement, but lua has been on my todo for a while.
But why calling it from occ then ? Shouldn’t it be possible to run directly as a flow, with the lua script calling the tesseract binary to do the ocr ?
So I finally took a few moments to give it a try, and thanks to the documentation and examples, came up with this script which is way better than the shell wrapper.
Thanks for the documentation & examples. Just had a little bug with comment_create (handled in the lua code): when run with occ, it seems the script don’t have the user (users_find() returns nil), and comment_create fails. So workaround it by getting the file’ owner from metadata and impersonating it.
Now, my last issue is with flow, which doesn’t seem to trigger upon file update, but works with tags.