Automate in Linux - pierregermain/MyTux GitHub Wiki

Requisitos:

  • xdotools
  • xclip
  • wmctrl
  • zenity

Ejemplos

Copy / paste independientemente de si estoy o no en una terminal

pierre@7550 /usr/bin$ cat ctrc.sh                                                                                                                      1 ↵  
#!/bin/bash
# Get the window ID of the currently focused window
WINDOW_ID=$(xdotool getwindowfocus)

# Get the class of the currently focused window
WINDOW_CLASS=$(xprop -id $WINDOW_ID WM_CLASS)

# Check if the window class matches specific terminal classes
if echo "$WINDOW_CLASS" | grep -qE '("gnome-terminal"|"x-terminal-emulator"|"xfce4-terminal"|"konsole"|"xterm"|"lxterminal"|"mate-terminal"|"terminator")'; then
  # Simulate pressing Ctrl+C
  echo 'terminal'
  sleep 0.2;
  xdotool key key ctrl+shift+c;
else
  echo 'no terminal'
  sleep 0.2;
  xdotool key getactivewindow key ctrl+c;
fi

Copiar desde Calc (Lado izquierdo) a Chrome (Lado derecho)

#!/bin/bash
# Script para copiar desde Calc a Jira en Chrome
# Calc en un left, Jira en right
zenity --info --text="Click on the Calc cell. Have Jira opened with \"Log another\""
xdotool mousemove 482 374 click 1
# Issues
xdotool key --clearmodifiers Up;
sleep 0.1;
xdotool key --clearmodifiers Down;
sleep 0.1;
xdotool key getactivewindow key ctrl+c;
sleep 0.1;
xdotool key getactivewindow key Escape;
sleep 0.1;
xdotool key getactivewindow key ctrl+c;
sleep 0.1;
issue=$(xclip -selection clipboard -o)
sleep 0.1;
xdotool key Right

# Description
sleep 0.1;
xdotool key --clearmodifiers ctrl+c;
description=$(xclip -selection clipboard -o)
xdotool key Right

# Date
sleep 0.1;
xdotool key --clearmodifiers ctrl+c;
mydate=$(xclip -selection clipboard -o)
xdotool key Right

# datefrom
sleep 0.1;
xdotool key --clearmodifiers ctrl+c;
datefrom=$(xclip -selection clipboard -o)
xdotool key Right

# worked
sleep 0.1;
xdotool key --clearmodifiers ctrl+c;
worked=$(xclip -selection clipboard -o)
xdotool key Right

# ----- Lets input the data in the Jira window -----

#Description
xdotool mousemove 1338 729 click 1
echo "$description" | xclip -selection clipboard
xdotool key --clearmodifiers ctrl+a;
xdotool key --clearmodifiers ctrl+v;

#Issue
xdotool mousemove 1376 659 click 1
echo "$issue" | xclip -selection clipboard
xdotool key --clearmodifiers ctrl+v;
sleep 2;
xdotool key --clearmodifiers Return;
sleep 2;

#Date
xdotool mousemove 1380 890 click 1
echo "$mydate" | xclip -selection clipboard
sleep 1;
xdotool key --clearmodifiers ctrl+a;
sleep 1;
xdotool key --clearmodifiers ctrl+v;
sleep 1;
xdotool key --clearmodifiers Return;

#from
xdotool mousemove 1377 966 click 1
echo "$datefrom" | xclip -selection clipboard
xdotool key --clearmodifiers ctrl+a;
sleep 1;
xdotool key --clearmodifiers ctrl+v;
sleep 1;
xdotool key --clearmodifiers Return;

#worked
xdotool mousemove 1356 1022 click 1
echo "$worked" | xclip -selection clipboard
xdotool key --clearmodifiers ctrl+a;
sleep 1;
xdotool key --clearmodifiers ctrl+v;
sleep 1;
xdotool key --clearmodifiers Return;

sleep 1;

# Log Time
xdotool mousemove 1478 1188 click 1
sleep 1;

#
##Return to Calc
xdotool mousemove 482 374 click 1
sleep 0.1;
xdotool key --clearmodifiers Left;
sleep 0.1;
xdotool key --clearmodifiers Left;
sleep 0.1;
xdotool key --clearmodifiers Left;
sleep 0.1;
xdotool key --clearmodifiers Left;
sleep 0.1;
xdotool key --clearmodifiers Left;
sleep 0.1;
xdotool key --clearmodifiers ctrl+b;
sleep 0.1;
xdotool key --clearmodifiers Down;



Paste y siguiente pestaña en chrome

while true; do sleep 2;
xdotool click 1 \
&& xdotool key --clearmodifiers ctrl+v \
&& xdotool key --clearmodifiers key Escape \
&& xdotool key --clearmodifiers ctrl+Tab \
&& xdotool key --clearmodifiers super+Right
done;

Copiar y pegar dos campos a un campo

wmctrl -a " Google Chrome" && sleep 0.5s \
&& xdotool key Ctrl+a \
&& xdotool key Ctrl+c \
&& xdotool key --repeat 3 Tab \
&& xdotool key Ctrl+v \
&& xdotool key Shift+Tab \
&& xdotool key Ctrl+a \
&& xdotool key Ctrl+c \
&& xdotool key Tab \
&& xdotool key End \
&& xdotool key space \
&& xdotool key Ctrl+v ;

Copiar dos líneas y pegarlas en otro campo

Click y siguiente pestaña

while true; do sleep 1; xdotool key click 1; sleep 1; xdotool key --clearmodifiers ctrl+Tab; done

Mouse Move Relative

while true; do sleep 1; xdotool mousemove_relative 50 50 ;sleep 1; xdotool mousemove_relative -- -50 -50; done 

Scrolldown y click

xdotool key --clearmodifiers super+Left \
&& xdotool key End \
&& xdotool click 1 \
&& xdotool key --clearmodifiers super+Right \
&& xdotool key Up

Vagrant Up, Mount,vagrant ssh

Opens a new terminal with vagrant ssh, and an other one to the mounted vagrant

#/bin/bash
set -x
HOUSE='/home/pierre'
PATH_VAGRANT="$HOUSE/webapps/project-name-vagrant/"
PWD_MOUNT='password'
PATH_MOUNT="$HOUSE/webapps/project-name-sshfs"
cd $PATH_VAGRANT
vagrant halt
sleep 2
vagrant up
xdotool exec xfce4-terminal && sleep 1 && xdotool type "sh $PATH_VAGRANT/mount_sbbimmo.sh;" && xdotool key Return && xdotool sleep 2 && xdotool type $PWD_MOUNT && xdotool key Return
xdotool exec xfce4-terminal && xdotool sleep 2 && xdotool type "cd $PATH_MOUNT;git status" && xdotool key Return
xdotool exec xfce4-terminal && sleep 1 && xdotool type "cd $PATH_VAGRANT;vagrant ssh" && xdotool key Return

Move mouse to next display

#!/bin/bash
#
# Move the current mouse cursor to the next monitor.
#
# Only works on a horizontal monitor setup.
# Also works only on one X screen (which is the most common case).
#

#get mouse position
mdata=`xdotool getmouselocation`
echo $mdata

#display width
w=`xdotool getdisplaygeometry | cut -d" " -f1`
echo $w

#extract x/y coordinates
x=`echo "$mdata"|cut -f1 -d' '|cut -d: -f2`
y=`echo "$mdata"|cut -f2 -d' '|cut -d: -f2`

echo $x
echo $y

if [ $x -gt $w ](/pierregermain/MyTux/wiki/-$x--gt-$w-)
then
  x_new=`expr $x - $w`
else
  x_new=`expr $x + $w`
fi


# Move the cursor
xdotool mousemove $x_new $y

Script to make window smaller

pierre@7550 ~/Scripts/windows-manager$ cat windowsizesmall.sh                                                                                                                                                     
#!/bin/bash
# Script to make window  15% smaller (15% = 85/100)

win_id=$(xdotool getactivewindow) # Get active window id

# Use xwininfo, grep, and awk to extract window width and height
win_info=$(xwininfo -id $win_id)
win_width=$(echo "${win_info}" | grep 'Width:' | awk '{print $2}')
win_height=$(echo "${win_info}" | grep 'Height:' | awk '{print $2}')

new_width=$((win_width * 85 / 100))
new_height=$((win_height * 85 / 100))

xdotool windowsize $win_id $new_width $new_height