首先,我存储pid
一个积极的窗户。
active_window_pid=$(xdotool getactivewindow getwindowpid)
其次,我点击其他窗口,实际上是下面的函数。
mouse_click 4000 1000
第三,我想重新启动以前活跃的窗外,可惜没有成功。
xdotool search --pid $active_window_pid windowactivate
function mouse_click
function mouse_click {
# 1. activate window and wait for sync,
# we need to do this before each click,
# because the user may have clicked on some other window during the 2 second delay
# 2. move the mouse cursor to the given position and wait for sync
# 3. click the left mouse button
# 4. restore the original mouse cursor position and wait for sync
# 5. wait for 2 seconds
xdotool search --name "window name" windowactivate --sync
xdotool mousemove --sync $1 $2 \
click 1 \
mousemove --sync restore \
sleep 2
}
这次我做错了什么?有任何想法吗?
答案1
xdotool
至少在某些版本中存在错误。
错误字符串:
不能消耗 1 个参数;只有 0 个可用。这是一个错误。
错误跟踪器:
https://github.com/jordansisssel/xdotool/issues/14
错误解决方法:
设置--name "whatever"
function activate_window_via_pid {
# for the chrome browser there are multiple processes,
# therefore we must pick one of them,
# the last one seems to work
window_id=$(xdotool search --pid $1 --name "bug workaround" | tail -1)
xdotool windowactivate --sync $window_id
}