Fork me on GitHub

Herr Knedel/Short story: Desktop control with xDoTools and xClip

Created Sun, 04 Apr 2021 00:00:00 +0000 Modified Mon, 28 Mar 2022 18:08:47 +0000 Difficulty level: It may take a little longer

156 Words

In this tutorial I show how to control a Linux - desktop via Bash. The following packages are needed for the bash robot:

x
+
Terminal

$ apt-get install xdotool xclip

After that you can use all xdotool commands, for example:

#!/bin/bash

#mouse bewegen
xdotool mousemove 100 200 

#Mouse - Koordinaten erfassen
xdotool getmouselocation 

#Mouse-klick
xdotool click 1 

Mouse-Klick auf Koordinaten
xdotool mousemove 100 200 click 1 

#usw...

In the following example, the Firefox window is searched and a new tab is opened with the Ubuntu address:

WID=$(xdotool search firefox | head -n1)     ## Window-ID von Firefox ermitteln
xdotool windowactivate $WID
xdotool key "ctrl+t"                         ## neuen Reiter öffnen
xdotool key "ctrl+l"                         ## Fokussieren der Adressleiste
xdotool type --delay 100 "ubuntuusers.de"    ## Internetadresse eintippen
xdotool key "Return"                         ## Internetadresse aufrufen 

Why do you need xclip??

With xdotools/“ctrl c” you can copy content into the cache and read or process it with xclip in the bash script.