Use xdotool to control Linux desktop windows and input.
Installation
# Debian/Ubuntu
sudo apt install xdotool
# Fedora
sudo dnf install xdotool
# Arch
sudo pacman -S xdotool
Command Reference
Window Management
# 获取当前活动窗口
xdotool getactivewindow getwindowname
# 按名称查找窗口
xdotool search --name "Firefox"
# 激活窗口
xdotool windowactivate $(xdotool search --name "Firefox" | head -1)
# 最小化/最大化
xdotool windowminimize $(xdotool getactivewindow)
# 移动和调整大小
xdotool windowmove --sync $(xdotool getactivewindow) 100 100
xdotool windowsize --sync $(xdotool getactivewindow) 1200 800
Keyboard Input
# 输入文本
xdotool type "Hello World"
# 按键
xdotool key Return
xdotool key ctrl+c
xdotool key ctrl+shift+t
xdotool key super
Mouse Operations
# 移动鼠标
xdotool mousemove 500 300
# 点击
xdotool click 1 # 左键
xdotool click 3 # 右键
# 移动并点击
xdotool mousemove 500 300 click 1
Wait
# 等待窗口出现
xdotool search --sync --name "Save"
Note
- Only X11 is supported; under Wayland, use
ydotoolinstead - Some applications may not respond to xdotool's keyboard input