Xfce Forum

Sub domains
 

You are not logged in.

#1 2024-03-25 01:59:26

TechnicJelle
Member
From: The Netherlands
Registered: 2024-03-25
Posts: 4
Website

Start Screenshooter via CLI with specific Custom Action

Hi there!

I'll preface this by saying I'm a huge fan of XFCE, and have been for many years.
When I discovered custom actions in Screenshooter about an hour ago, I was immediately in love with them!

However, I have one small question.
In my Keyboard settings, in the Application Shortcuts, I have set up a couple different shortcuts for Screenshooter:

xfce4-screenshooter -w    Print
xfce4-screenshooter -f    Shift+Print
xfce4-screenshooter -rc   Shift+Super+S

And I was wondering if it was possible to add another one, with which I could select an area (-r) and then pipe it into one of the Custom Actions that I've set up, like an OCR one or the QR code one.
It would be really nice if I could just hit a hotkey, select an area, and then get the text from that area copied into my clipboard immediately.
Almost like -rc, except instead of an image, it's text.

Of course, I already looked in the --help menu, but I couldn't see anything referring to the new Custom Actions there.
I also looked at the bug tracker, but nothing about this there either.

Thanks for reading!
And thanks for the super amazing software, too!

Last edited by TechnicJelle (2024-03-25 02:05:32)

Offline

#2 2024-03-25 02:51:53

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,992

Re: Start Screenshooter via CLI with specific Custom Action

Hello and welcome.

What is the source that you are using to capture the image to OCR? An image file with text?

Here is an interesting experiment. With xclip and tesseract (and the appropriate tesseract language data file) installed, run the following command:

xfce4-screenshooter -r -s /tmp/save.png && tesseract /tmp/save.png - | xclip

...when prompted with the screenshooter crosshairs, select the text you want. Then look into your clipboard.

If it works satisfactorily, create a shortcut for it.


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#3 2024-03-25 04:04:06

TechnicJelle
Member
From: The Netherlands
Registered: 2024-03-25
Posts: 4
Website

Re: Start Screenshooter via CLI with specific Custom Action

Hi!

Yes, the source for the image would be a normal xfce4-screenshooter -r.
Currently, I'm just using the examples from the docs, but I'm planning on looking into a different program to handle the OCR-ing.
So currently, I'm just using

gimagereader-gtk %f

But what you suggested sounds exactly like what I wanted!

I tried it out just now, and almost works.
It just doesn't actually copy the text to the clipboard.

If I run it from a terminal, instead of the keyboard shortcut, it also doesn't work.
And if I leave out the last pipe into xclip, it prints exactly what I want!
So there must be something not quite right with that yet.
I looked it up, and it seems to be an issue with the fact that xclip relinquishes control over the clipboard too soon, so the copied text gets lost, I think? (source)
So I tried that nohup program, but I don't think I'm using it right, because it still doesn't work.

It did print this a little while after I ran it, though:

Use the -Toops @ option (default). Make the X selection indefinitely available, until another
process requests ownership of the X selection.

However, binding the program to a keyboard shortcut kil the xclip daemon after it returns. This
behavior is not present when launching the program from a terminal. The -verbose option keeps
the program running in the foreground, which causes the terminal to be kept around as well.

To keep the xclip daemon running, with no terminal window visible, an option is to use the
nohup. program. It runs a command which will have the init process as PPID (e.g. systemd).

But I think it's a bit too late in the night for me to fully understand what this entails.

Oh wait, scratch that!
It is in the clipboard, but it's just not in the Ctrl+V clipboard, or something like that?
I can paste it by pressing the middle mouse button, instead, according to Clipman.

Maybe I just need to study how clipboards work on Linux a bit more.
Thanks for the leg-up already, in any case!
I'm heading to bed, now, though.

Offline

#4 2024-03-25 10:31:43

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,992

Re: Start Screenshooter via CLI with specific Custom Action

If you have clipman installed and on your panel, make sure "Sync mouse selections" is selected. For me Ctrl+V works.

Some initial links to get a better understanding of clipboards:
- xfce4-clipman doc page
- arch wiki page


Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#5 2024-03-25 21:06:24

TechnicJelle
Member
From: The Netherlands
Registered: 2024-03-25
Posts: 4
Website

Re: Start Screenshooter via CLI with specific Custom Action

I didn't know about that setting, thanks!

When I run the command from my terminal, now, it indeed works exactly like I wanted to! Thank you!

However, when I copy that command into my keyboard shortcuts, it doesn't work any more...
I'll read up more on the way Clipman (and clipboards on Linux and X11 in general) work!

Offline

#6 2024-03-25 21:30:05

ToZ
Administrator
From: Canada
Registered: 2011-06-02
Posts: 10,992

Re: Start Screenshooter via CLI with specific Custom Action

TechnicJelle wrote:

However, when I copy that command into my keyboard shortcuts, it doesn't work any more...

The Keyboard shortcuts command can't handle special characters well. Try running them within a temporary shell:

sh -c 'xfce4-screenshooter -r -s /tmp/save.png && tesseract /tmp/save.png - | xclip'

Please remember to mark your thread [SOLVED] to make it easier for others to find
--- How To Ask For Help | FAQ | Developer Wiki  |  Community | Contribute ---

Offline

#7 2024-03-25 21:40:47

TechnicJelle
Member
From: The Netherlands
Registered: 2024-03-25
Posts: 4
Website

Re: Start Screenshooter via CLI with specific Custom Action

Yeah, now it works!! Thank you so much!!

However, I think that "Sync mouse selections" setting does more than I want it to.
It seems as though it now copies everything I select, even before I press Ctrl+C.
I'm assuming this is a normal thing, but is there maybe a way to turn that off?

In fact, I noticed this when opening the keyboard shortcuts section.
I double-clicked on the entry for the Screenshooter OCR, and the command was automatically pre-selected for me.
So when I pressed Ctrl+V to paste the command I had copied from your message, it did not paste at all.
It seemed like nothing happened, but that's because it was pasting itself overtop itself.
Very interesting behaviours!


Maybe I'll stick to keeping that option off, after all, and having to remember that, to paste the OCR'd text, I have to click my middle mouse button, instead of using Ctrl+V, like normal.

Last edited by TechnicJelle (2024-03-25 21:42:27)

Offline

#8 2024-04-03 01:24:08

cfgnunes
Member
Registered: 2024-04-03
Posts: 2

Re: Start Screenshooter via CLI with specific Custom Action

I have some examples of OCR custom actions in my project here:

https://github.com/cfgnunes/nautilus-scripts

Offline

Board footer

Powered by FluxBB