快速入门 cliclick

466 阅读4分钟

探索 mac 上的自动化操作,结合 automator or script 效果更佳使用教程

如果使用terminal执行命令,则需要打开设置-隐私与安全-辅助功能,给 terminal 应用授权

安装 cliclick

brew install cliclick

自动输入并搜索 cliclick, 移动鼠标至x = 200,y = 100,单击,输入cliclick, 模仿键盘输入 enter

cliclick m:200,100 c:. t:cliclick kp:enter

拖动指定位置元素(400,200)到指定位置(500,500)

cliclick m:400,200 c:. dd:. dm:500,500 du:. 

每个操作等待固定时间

cliclick -w 200 

打印当前坐标到 pos 文件中 选定输出方式 e.g.

cliclick -d ./pos  p:.  

从指定文件中读取命令行参数

touch ./arg
echo "p:hello-world"
cliclick -f ./arg

参数详解

# 鼠标右键指定位置
# rc:x,y  Will RIGHT-CLICK at the point with the given coordinates.
#         Example: “rc:12,34” will right-click at the point with x coordinate
#         12 and y coordinate 34. Instead of x and y values, you may
#         also use “.”, which means: the current position. Using “.” is
#         equivalent to using relative zero values “c:+0,+0”.

# 鼠标移动至指定位置
# m:x,y   Will MOVE the mouse to the point with the given coordinates.
#         Example: “m:12,34” will move the mouse to the point with
#         x coordinate 12 and y coordinate 34.

# 组合键
# kd:keys Will trigger a KEY DOWN event for a comma-separated list of
#         modifier keys. Possible keys are:
#           - alt
#           - cmd
#           - ctrl
#           - fn
#           - shift
#         Example: “kd:cmd,alt” will press the command key and the
#         option key (and will keep them down until you release them
#         with another command)

# 单个键按下 假设弹出聚焦需要执行 cliclick kd:cmd kp:space
# kp:key  Will emulate PRESSING A KEY (key down + key up). Possible keys are:
#           - arrow-down
#           - arrow-left
#           - arrow-right
#           - arrow-up
#           - brightness-down
#           - brightness-up
#           - delete
#           - end
#           - enter
#           - esc
#           - f1
#           - f2
#           - f3
#           - f4
#           - f5
#           - f6
#           - f7
#           - f8
#           - f9
#           - f10
#           - f11
#           - f12
#           - f13
#           - f14
#           - f15
#           - f16
#           - fwd-delete
#           - home
#           - keys-light-down
#           - keys-light-toggle
#           - keys-light-up
#           - mute
#           - num-0
#           - num-1
#           - num-2
#           - num-3
#           - num-4
#           - num-5
#           - num-6
#           - num-7
#           - num-8
#           - num-9
#           - num-clear
#           - num-divide
#           - num-enter
#           - num-equals
#           - num-minus
#           - num-multiply
#           - num-plus
#           - page-down
#           - page-up
#           - play-next
#           - play-pause
#           - play-previous
#           - return
#           - space
#           - tab
#           - volume-down
#           - volume-up
#         Example: “kp:return” will hit the return key.

# 三击
# tc:x,y  Will TRIPLE-CLICK at the point with the given coordinates.
#         Example: “tc:12,34” will triple-click at the point with x
#         coordinate 12 and y coordinate 34. Instead of x and y values,
#         you may also use “.”, which means: the current position.
#         Note: If you find that this does not work in a target application,
#         please try if double-clicking plus single-clicking does.

# 键盘释放
# ku:keys Will trigger a KEY UP event for a comma-separated list of
#         modifier keys. Possible keys are:
#           - alt
#           - cmd
#           - ctrl
#           - fn
#           - shift
#         Example: “ku:cmd,ctrl” will release the command key and the
#         control key (which will only have an effect if you performed
#         a “key down” before)

# dm:x,y  Will continue the DRAG event to the given coordinates.
#         Example: “dm:112,134” will drag and continue to the point with x
#         coordinate 112 and y coordinate 134.

# 单机
# c:x,y   Will CLICK at the point with the given coordinates.
#         Example: “c:12,34” will click at the point with x coordinate
#         12 and y coordinate 34. Instead of x and y values, you may
#         also use “.”, which means: the current position. Using “.” is
#         equivalent to using relative zero values “c:+0,+0”.

# 在指定坐标开始拖动
# dd:x,y  Will press down to START A DRAG at the given coordinates.
#         Example: “dd:12,34” will press down at the point with x
#         coordinate 12 and y coordinate 34. Instead of x and y values,
#         you may also use “.”, which means: the current position.

# 等待多少秒
# w:ms    Will WAIT/PAUSE for the given number of milliseconds.
#         Example: “w:500” will pause command execution for half a second

# 显示当前坐标或指定文字
# p[:str] Will PRINT the given string. If the string is “.”, the current
#         MOUSE POSITION is printed. As a convenience, you can skip the
#         string completely and just write “p” to get the current position.
#         Example: “p:.” or “p” will print the current mouse position
#         Example: “p:'Hello world'” will print “Hello world”

# 在指定坐标结束拖动
# du:x,y  Will release to END A DRAG at the given coordinates.
#         Example: “du:112,134” will release at the point with x
#         coordinate 112 and y coordinate 134.

# 打印当前坐标 rgb
# cp:str  Will PRINT THE COLOR value at the given screen location.
#         The color value is printed as three decimal 8-bit values,
#         representing, in order, red, green, and blue.
#         Example: “cp:123,456” might print “127 63 0”

# 双击
# dc:x,y  Will DOUBLE-CLICK at the point with the given coordinates.
#         Example: “dc:12,34” will double-click at the point with x
#         coordinate 12 and y coordinate 34. Instead of x and y values,
#         you may also use “.”, which means: the current position.

# 输入文字 最好先选中输入框(移动到输入框上,并单击)
# t:text  Will TYPE the given TEXT into the frontmost application.
#         If the text includes space(s), it must be enclosed in quotes.
#         Example: “t:Test” will type “Test” 
#         Example: “t:'Viele Grüße'” will type “Viele Grüße”