Mac系统自动化脚本

Posted on 2024-04-06 14:58  LIN_Lighto  阅读(113)  评论(0编辑  收藏  举报

使用pyautogui创建脚本
pip install pyautogui

授予终端或其他运行程序以屏幕控制权限

PyClick.py

import pyautogui
import time

#按钮坐标:Mac可通过command+shift+4屏幕截图功能查看
b1 = (25,11)
b2 = (38,38)

#流程:将各按钮坐标写入pipe中
pipe = [b1,b2]

#请授予运行程序以屏幕控制权限
#——————————————————————————
#点击
def click(btn,sep):
    pyautogui.moveTo(btn)
    pyautogui.click()
    time.sleep(sep)

def exce(pipe,num=1,sep=0.3):
    print('pipe executing:', pipe)
    for i in range(num):
        for btn in pipe:
            click(btn,sep)
#——————————————————————————
exce(pipe,2,0.3) #执行pipe,2次,停顿0.3秒

Copyright © 2024 LIN_Lighto
Powered by .NET 9.0 on Kubernetes