How to run selected text using keyboard shortcut joined together with a command in background? - linux

I am trying to be able to select text anywhere within my manjaro linux system and run it along with a TTS text to speech program. The program is called google_speech and it got a really clear default voice and is really easy to use, however I am finding it hard to implement what I want to do with it...
The program is ran by the following command:
$ google_speech -l en "I am just a robot but one day I plan to rule humans"
so I am trying to be able to select text and press a keyboard shortcut and the text will automatically be importing here:
$ google_speech -l en "HERE"
and ran as a command in the background hopefully without having to open a terminal window but if so then thats totally fine... I was thinking xclip would be able to do this but I can figure out what command or options I need to be using... my research so farhas gotten me nowhere...
Thanks you so much for your time and skills...

Related

How to navigate from running python script in ubuntu terminal?

I am currently running a python3 script in Ubuntu server 18.04. When i type new commands into the command line it just prints the commands. My terminal window looks like this:
mitch#server:`$ cd /home/mitch/folder
mitch#server:`/folder$ python3 main.py
file running ...
text i input just shows like this
I need to keep the script running and run other commands, how do i navigate back to:
mitch#server:`
I'm new to servers/Ubuntu/commands so this may seem trivial! Thank you
So you can't "navigate" back to that, since you're technically already there, you're just running a script in your shell which is occupying your shell - think of it like you opened a program in full screen.
But you have a few options:
The most basic is to run the script in the 'background' this is a simple as adding a & to the end of your command (note that it will still send any message from the script into your terminal - if your script is programmed to send messages that is).
Another option is to use a terminal multiplex like which lets you have multiple terminals open, as well as split screen terminals and many other features. One of the more popular multiplexers is called tmux, just keep in mind that it does have a bit of a learning curve to it, but is extremely useful once you learn it.

pywinauto (or others): to emulate Ctrl+A & Ctrl+X anywhere (not only on specified app)

I'm looking for a way to generate a ctrl+A (select all), and then ctrl+x in a python script. I know how to generate this in a specific app (pywinauto and other modules do that). But I'm looking for a way to send these keys in any apps (in any field of the active windows). I want to launch the python script containing these keys anywhere (the script will be launch using a key shortcut. Details below (1))
EDIT: I'm NOT trying to copy/past in the command windows (cf. the 2 last sentences). My script send the keys in the command windows, but that's the problem I'm trying to solve...
Using python pywinauto (or Ctypes or other modules)
I tried several propositions listed here with the same result.
I thought pywinauto could do it. Following pywinauto latest documentation I tried that:
open an (any) app containing a text field (that's the active windows)
place the cursor where you want to make the select all + cut/past
run the script bellow using an shortcut (so you won't leave the active windows)
from pywinauto.keyboard import SendKeys
SendKeys('^a^x')
Result
The code only print ^A^X in the python console. It doesn't do what it's suppose to do in the field of the active window (where I placed my cursor): it doesn't select all + cut the text.
Using autohotkey:
The only way I found to simulate a real crtl+A ctrl+C is by using autohotkey (it works but it's not a python solution):
save the code bellow in my AHK script: select_copy.ahk
Send, ^a
Send, ^x
create another AHK script called shortcut.ahk where you will specify a shortcut to launch select_copy.ahk (shortcut.ahk sould run constantly in windows background (2))
!^+G:: Run select_copy.ahk , C:\Users\Me\Desktop
(meaning: when I hit ctrl+alt+shift+G run the script select_copy.ahk)
result:
It works. when I call the ahk, it select/cut things in the active windows.
A combination of both did not work
I tried to launch the select_copy.ahk from within a python script (using subprocess.call) but I ended up with the same result than pywinauto (or Ctypes): it only prints ^A^X in the consol, but doesnt select&cut. So I'm wondering if python could really do what autohotkey does.
(1) What the script will do: I will launch the script (using a shortcut key) on one or another html editor, it will cut all the text, parse its source code, make some change put back the datas in the clipbboard, and past it. I'm only missing the first part (select all + cut) and the last part (past).
(2) It's not the big deal since shortcut.ahk contains also all my other ahk shortcuts and scripts.
Your AutoHotKey script should work, and does on my machine. However, I recommend that you just have one shortcut.ahk file containing the following:
!^+G::
Send, ^a
Send, ^x
Return
...and then put this in your python file:
subprocess.call("C:\\Path\\To\\AutoHotKey.exe /r C:\\Path\\To\\shortcut.ahk")
replacing the paths with wherever the AutoHotKey executable is, and wherever the shortcut.ahk file is.
Just as a side note: !^+G:: triggers on Alt+Shift+Ctrl+G, not Shift+Ctrl+G as you wrote in your question:
(meaning: when I hit ctrl+shift+G run the script select_copy.ahk)
EDIT: Also, from the phrase in the python console in your question it seems like you're trying to select all and then cut it in CMD. This will not work at all. Instead, if you want to simply clear the console, just use the command cls (Windows only; use clear in Linux). If you want to copy the entire console output and then clear it (i.e. cut) you're gonna need something different.

python3 input using sublime text 3

I am trying to use the input feature on python for my program. I installed SublimeREPL but I still cant seem to figure out how to provide an input for my program. (coming from a complete beginner)
Using input from within an editor can be tricky. A simple solution would be to run your program from the command line. Open a terminal and change into the directory where your script user_inputs_intro.py is located and type:
python user_inputs_intro.py
Now, you will see the Tell me something: and should be able to type something that will be echoed back after you press enter.

How to read text from clipboard?

Is that possible to read text from clipboard on Linux udner X?
I select some text in a browser (Firefox for example) then click Edit->Copy.
Now I need this text in my application. I am using plain XLib. No GTK, no QT.
I do not want to use external apps like xsel. I studiet xsel source code, DAMN it is over 1000 lines. In Windows I am used to GetCLipboardTextW() one function call. That's all I need. Why is this so sophisticated? I have read this already:
http://www.sbin.org/doc/Xlib/chapt_12.html
And some more, I know there are many kinds of clipboards in X, selections, cut buffers etc. It does not help! Give me some code that compiles and works. No external libraries please no sudo apt-get install something, no "Are you using KDE(GNOME/whatever)?".
xclip is just 600 lines of code, but much of it seems to be due to processing command line options, reading input files, etc. Looking at main and doOut the core of what it does seems to be:
XOpenDisplay(...)
XCreateSimpleWindow(...)
XSelectInput(...)
XFetchBuffer(...) or xcout(...)
XCloseDisplay(...)

Node command line interface change

I'm making a command interface for a node server, but I have reached a point that I want it to look better.
I want to have the console so you enter a command at the bottom of the terminal screen, you hit enter, and it adds the reply to the actual command line.
If you have ever run a minecraft bukkit server from the command line, you should know what I'm talking about.
Here's a picture of what I'm talking about if you still don't understand. Imagine this was in terminal, and ignore the scroll bars: http://cl.ly/1K0h1V0r0H3f3U3t3L22
Is there anyway to set the console to look like this without having to make your own program for it or having the screen reprint all the other info to fake that look?
I have not done this, but I believe something similar is possible with very little effort by using Node.js REPL. You can override the eval parameter to provide your own command processing.
It would not have the exact look you are wanting, but it will be an interactive prompt that you can utilize (more similar to a Windows command shell or a Linux shell).
If you want the exact look from your screenshot, I don't believe that there is any Node.js module that will help you. There are some that allow you to use colors in the console, and some basic highlighting (e.g. bold), but nothing that gives you complete control over the console screen.

Resources