#!/usr/bin/env bash
while true; do
if xprintidle | grep -q 3000; then
xdotool mousemove_relative 1 1
fi
done
Run Code Online (Sandbox Code Playgroud)
目前我可以检查是否xprintidle等于 3000,如果是,则执行xdotool. 但我想检查是否xprintidle大于或等于 3000 然后执行xdotool. 我怎样才能做到这一点?
Ger*_*csy 15
if [ $xprintidle -ge 3000 ]; then
[...stuff...]
Run Code Online (Sandbox Code Playgroud)
这是一个快速解释:
您可以直接使用bash's Arithmetic Expansion来比较整数:
#!/usr/bin/env bash
while :; do
(( $(xprintidle) >= 3000 )) && xdotool mousemove_relative 1 1
sleep 0.5
done
Run Code Online (Sandbox Code Playgroud)
如果你只想要单个命令,&&是一个简单的方法。或者,使用if:
#!/usr/bin/env bash
while :; do
if (( $(xprintidle) >= 3000 )); then
xdotool mousemove_relative 1 1
fi
sleep 0.5
done
Run Code Online (Sandbox Code Playgroud)
我向sleep循环添加了一个调用,每次运行暂停半秒——根据需要进行调整。