如何修改 xdotool 输出以将它们导出为变量?

Tim*_*Tim 3 command-line xdotool

我正在执行这个命令:

xdotool getmouselocation --shell

它给了我:

X=1020
Y=563
SCREEN=0
WINDOW=90183822
Run Code Online (Sandbox Code Playgroud)

如何将 X 值和 Y 值放入变量中,以便稍后在脚本中使用?

Syl*_*eau 6

您将在xdotool 手册页中找到答案:

getmouselocation [--shell]
       Outputs the x, y, screen, and window id of the mouse cursor.
       Screen numbers will be nonzero if you have multiple monitors
       and are not using Xinerama.

       --shell
           This makes getmouselocation output shell data you can eval. Example:

            % xdotool getmouselocation --shell
            X=880
            Y=443
            SCREEN=0
            WINDOW=16777250

            % eval $(xdotool getmouselocation --shell)
            % echo $X,$Y
            714,324
Run Code Online (Sandbox Code Playgroud)