How do I send keys programmatically (simulated key typing) in Linux Mint? - clipboard

I have passwords saved in a password manager (KeePass running on Wine) on Linux Mint.
The login site that I have does not allow pasting the password. The password is a 40 random characters and special characters which makes it difficult and tedious to type manually using keyboard.
I want to copy the password from the KeePass and then run some script (like AutoIt, AutoIt is not supported on Linux Mint) that reads the clipboard data (the copied password) and sends character by character (simulate typing by keyboard) to the password field in the browser.
How do I achieve this on Linux Mint 20? If AutoIt was working on Linux Mint I would have been happy.
I found xdotool but cannot figure out a way to set the focus to Firefox window.

I found the solution
pass=`clipit -c`
xdotool search --sync --onlyvisible --name "My Bank" windowactivate
xdotool type --delay 500 $pass

Related

Is there any way to fetch the title of a chromium-browser window via script or command?

I'm working on a project using Libre LePotato with Raspbian for a basic display kiosk. It launches chromium-browser to a specific url, then uses xdotool to type the username and password and hit enter. Once logged in the page refreshes every 5 minutes. Eventually the page forgets the login credentials and needs to be logged into again. The URL does not change between the login screen and the actual display page, but the title of the window does. Is there any way for me to fetch the title of the window? That way I can just create an if/then script that runs xdotool when the window title is Login.
I've tried setting the device up to reboot more frequently in order to hopefully reset the memory cache and log in again on boot up, but the issue occurs too frequently and constant rebooting on a display does not look good.
The proper way to automate this would be through the use of Selenium, Playwright or Puppeteer (I prefer Puppeteer). If you insist though, you can use wmctrl.
For example, I'm using Brave, and let's say the normal output is this (I use Brave Browser):
$ wmctrl -l | grep -i brave
...
0x05400003 0 nullptr Home | Codewars - Brave
...
It lists the window id, a bunch of other stuff along with the title.
Now, the following is the output, when I'm on the sign-in page:
$ wmctrl -l | grep -i brave
...
0x05400b8b 0 nullptr Sign in | Codewars - Brave
...
With that knowledge, creating a script is relatively simple:
#!/usr/bin/env
if wmctrl -l | grep -q 'Sign in | Codewars - Brave'; then
printf '%s\n' 'about to sign in'
else
printf '%s\n' 'not signing in'
fi
Since this is all in a Kiosk, I figure that you won't have any other windows that potentialy interfere with the logic (ex. two codewars windows open at once)

Windows cmd simulate console input a command

I need to write a batch script which connects to a vpn automatically when username and password is saved somewhere (Ex: in a file). VPN client is openconnect which provides a CLI but the problem is user input needs to be provided interactively to the command in order for it to complete.
See the output below when I run :
openconnect <serverhostname>
OUTPUT
POST https://<serverhostname>/
Connected to <serverhostname>:443
SSL negotiation with <serverhostname>
Server certificate verify failed: signer not found
Certificate from VPN server "<serverhostname>" failed verification.
Reason: signer not found
To trust this server in future, perhaps add this to your command line:
--servercert pin-sha256:<somesha>
Enter 'yes' to accept, 'no' to abort; anything else to view:
So I basically have to type yes manually and press Enter (it also prompts for further input), this needs to be automated in a script. Also, it's worth noting that the output is suggesting to provide --server-cert option and I could do that but when it asks the password, there's no option for it.
I tried putting the input lines in a file and redirecting that to the stdin of the command (which did not work but same the method worked on zsh on linux)
openconnect <serverhostname> < inputfile.txt
I also tried piping to stdin of the command which also didn't work.
I think the particular command doesn't read from stdin but directly from the console somehow which I really don't know how, but I could find a bit of information about something called "CON" on cmd.
Any solution is highly appreciated.

Can I dump the source of a live Chromium window to a string?

I'm using xdotool to open a Chromium browser and click a few things , but I'm wondering if I can get the source code of the live window it's using and dump it into a string to check if the source contains a particular string.
I know a wget can get me the source of a window , but what I want is the window that's already open as it will contain the string I want, but the wget option may not.
How can I do that?
If ctrl+U (show source) can be used, it will save your time, but if you need to inspect live HTML, try this xdotool script:
#!/usr/bin/env xdotool
search --sync --onlyvisible --name chrome
windowactivate --sync
key Ctrl+Shift+C
sleep 0.5
key Down
sleep 0.5
key ctrl+F
sleep 1
type "What you try to find"
key Return
Save as 'xdotool_script', then run it like you executing bash script
$ chmod +x xdotool_script
$ ./xdotool_script`

Using script to remotely execute whiptail script

I am trying to execute a bash script that contains whiptail remotely through ssh. The problem is that ssh won't show any of the whiptail UI.
What would be the best way to display the whiptail prompts on a local computer?
The script is an interactive script on a remote server that needs to be triggered (and the prompts need to be answered by a user) through a script on a the local machine.
Is this the Whiptail you're talking about?
To interact with a Text-based UI (TUI), you need to run ssh with the -t flag like this
ssh -t user#host.name 'whiptail --title "Example Dialog" --msgbox "This is an example of a message box. You must hit OK to continue." 8 78'
The above command is tested to work. Take note that you have to put the entire command in quotes esp. if it has flags.

How can I use another user's display

I'm using xdotool in a SSH connection logged in as root, I'm setting DISPLAY=":0.0" which is what echo $DISPLAY on the logged user says. But I get a error unless I su to the other user:
root#sb:~# export DISPLAY=":0.0"
root#sb:~# xdotool getactivewindow
No protocol specified
No protocol specified
Error: Can't open display: (null)
Segmentation fault (core dumped)
geerm#sb:~$ export DISPLAY=":0.0"
geerm#sb:~$ xdotool getactivewindow
41943046
Is this even possible? If so, what do I need to change to use the logged in user's session?
By default, most X servers disallow other users displaying to each other's screens. If you want to disable this protection, you might be able to using xhost.
Try:
export DISPLAY=his_xserver_ip:0.0
and probably you need to add the IP allowed to connect to his xserver to his xhosts thru xhost +ip_to_connnect_from
http://www.xfree86.org/current/X.7.html

Resources