本文实现利用workbuddy来 实现一个批量化的 复杂任务示例:
要完成的目标. 批量自动化地让 workbuddy实现 阅读链接, 先转纯文本保存, 再写出总结摘要保存, 最后提取10大关键字保存.
1. 第一步: 让workbuddy写一个python程序, 这个python程序能 向workbuddy提交任务运行.
workbuddy写的代码如下:
py
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
WorkBuddy Helper
================
读取与本脚本同目录的 task.txt,将其内容粘贴到 WorkBuddy 工作台输入框,
并模拟发送动作。
用法:
python workbuddy_helper.py
python workbuddy_helper.py --file other_task.txt --window WorkBuddy --no-confirm
python workbuddy_helper.py --send-mode click --btn-x 1200 --btn-y 980
依赖(运行时自动安装): pywin32, pyautogui, pyperclip
注意:
- 运行前请确保 WorkBuddy 桌面端已打开且窗口可见。
- 默认用 Enter 键发送;若发送方式是点击按钮,请用 --send-mode click
并通过 --btn-x / --btn-y 指定发送按钮的屏幕坐标。
- 中文内容通过剪贴板粘贴,支持多行文本。
- 紧急中止:把鼠标快速移到屏幕左上角(pyautogui FAILSAFE)。
"""
import os
import sys
import time
import subprocess
import argparse
def ensure_packages():
"""运行时自动安装缺失依赖。"""
deps = {
'win32gui': 'pywin32',
'pyautogui': 'pyautogui',
'pyperclip': 'pyperclip',
}
missing = []
for mod, pkg in deps.items():
try:
__import__(mod)
except ImportError:
missing.append(pkg)
if missing:
print(f'[依赖] 正在安装: {", ".join(missing)}')
subprocess.check_call(
[sys.executable, '-m', 'pip', 'install', *missing],
stdout=subprocess.DEVNULL,
)
print('[依赖] 安装完成。')
ensure_packages()
import win32gui
import win32con
import ctypes
import pyautogui
import pyperclip
# pyautogui 安全设置
pyautogui.FAILSAFE = True
pyautogui.PAUSE = 0.1
# 默认配置
DEFAULT_WINDOW_KEYWORD = 'WorkBuddy'
DEFAULT_SEND_MODE = 'enter' # enter | click
DEFAULT_CLICK_Y_RATIO = 0.85 # 输入框在窗口纵向位置(0=顶, 1=底)
DEFAULT_PRE_DELAY = 1.5 # 激活窗口后等待秒数
DEFAULT_CONFIRM_SECONDS = 3 # 发送前倒数秒数(0=不确认直接执行)
def find_window(keyword):
"""按标题关键字查找可见窗口句柄。"""
found = []
def _cb(hwnd, _):
if win32gui.IsWindowVisible(hwnd):
title = win32gui.GetWindowText(hwnd)
if title and keyword.lower() in title.lower():
found.append((hwnd, title))
win32gui.EnumWindows(_cb, None)
return found
def force_foreground(hwnd):
"""强制将目标窗口置到前台。"""
user32 = ctypes.windll.user32
# 恢复最小化状态
win32gui.ShowWindow(hwnd, win32con.SW_RESTORE)
# ALT 键技巧绕过 SetForegroundWindow 的前台窗口限制
user32.keybd_event(win32con.VK_MENU, 0, 0, 0)
user32.keybd_event(win32con.VK_MENU, 0, win32con.KEYEVENTF_KEYUP, 0)
try:
win32gui.SetForegroundWindow(hwnd)
except Exception:
pass
def click_input_area(hwnd, y_ratio):
"""点击窗口中输入框大致区域以聚焦输入框,返回点击屏幕坐标。"""
left, top, right, bottom = win32gui.GetWindowRect(hwnd)
cx = (left + right) // 2
cy = int(top + (bottom - top) * y_ratio)
pyautogui.click(cx, cy)
time.sleep(0.3)
return cx, cy
def paste_text(text):
"""通过剪贴板粘贴文本(支持中文与多行)。"""
pyperclip.copy(text)
time.sleep(0.2)
pyautogui.hotkey('ctrl', 'a') # 全选清空旧内容
time.sleep(0.1)
pyautogui.hotkey('ctrl', 'v') # 粘贴
time.sleep(0.4)
def send_enter():
pyautogui.press('enter')
def send_click(x, y):
pyautogui.click(x, y)
time.sleep(0.2)
def read_task(path):
with open(path, 'r', encoding='utf-8') as f:
return f.read().strip()
def main():
parser = argparse.ArgumentParser(
description='将 task.txt 内容提交到 WorkBuddy 输入框并发送'
)
here = os.path.dirname(os.path.abspath(__file__))
parser.add_argument('--file', default=os.path.join(here, 'task.txt'),
help='任务文件路径(默认同目录 task.txt)')
parser.add_argument('--window', default=DEFAULT_WINDOW_KEYWORD,
help='窗口标题关键字(默认 WorkBuddy)')
parser.add_argument('--send-mode', choices=['enter', 'click'],
default=DEFAULT_SEND_MODE, help='发送方式')
parser.add_argument('--btn-x', type=int, default=0,
help='发送按钮屏幕 X 坐标(send-mode=click 时使用)')
parser.add_argument('--btn-y', type=int, default=0,
help='发送按钮屏幕 Y 坐标(send-mode=click 时使用)')
parser.add_argument('--click-y-ratio', type=float, default=DEFAULT_CLICK_Y_RATIO,
help='输入框在窗口纵向比例(默认 0.85)')
parser.add_argument('--no-click', action='store_true',
help='不点击输入框区域(假设窗口激活后输入框已聚焦)')
parser.add_argument('--pre-delay', type=float, default=DEFAULT_PRE_DELAY,
help='激活窗口后等待秒数')
parser.add_argument('--confirm', type=int, default=DEFAULT_CONFIRM_SECONDS,
help='发送前倒数秒数,0=不确认直接执行')
args = parser.parse_args()
# 1. 读取任务内容
if not os.path.exists(args.file):
print(f'[错误] 找不到任务文件: {args.file}')
sys.exit(1)
text = read_task(args.file)
if not text:
print('[错误] task.txt 为空')
sys.exit(1)
print(f'[1/4] 已读取任务内容({len(text)} 字符): {args.file}')
# 2. 查找窗口
windows = find_window(args.window)
if not windows:
print(f'[错误] 未找到标题包含 "{args.window}" 的窗口,请确认 WorkBuddy 已打开')
sys.exit(1)
hwnd, title = windows[0]
print(f'[2/4] 已找到窗口: {title}')
# 3. 激活窗口并聚焦输入框
force_foreground(hwnd)
time.sleep(args.pre_delay)
if not args.no_click:
cx, cy = click_input_area(hwnd, args.click_y_ratio)
print(f'[3/4] 已激活窗口并点击输入框区域 ({cx}, {cy})')
else:
print('[3/4] 已激活窗口(跳过点击输入框)')
# 4. 粘贴并发送
if args.confirm > 0:
print(f'[4/4] {args.confirm} 秒后粘贴并发送...(鼠标移到屏幕左上角可中止)')
for i in range(args.confirm, 0, -1):
print(f' {i}...')
time.sleep(1)
else:
print('[4/4] 开始粘贴并发送...')
paste_text(text)
print(' 已粘贴文本')
if args.send_mode == 'enter':
send_enter()
print(' 已按 Enter 发送')
else:
if args.btn_x == 0 and args.btn_y == 0:
print('[错误] click 模式需要提供 --btn-x 和 --btn-y')
sys.exit(1)
send_click(args.btn_x, args.btn_y)
print(f' 已点击发送按钮 ({args.btn_x}, {args.btn_y})')
print('完成。')
if __name__ == '__main__':
main()
第二步: 用你最熟悉的脚本语言去 利用刚才python程序完成 批量自动化.
笔者选择了apl.
apl
/*
这是个自动阅读文章的测试.
这个任务借助 workbuddy来完成阅读.
*/
include "/RY_OS/lib/sandbox/sandbox.apl";
<LISTEXT $$urls>
37.4K Star!开源AstrBot,让AI无缝嵌入所有聊天软件
https://www.toutiao.com/article/7665338880299762227/?app=news_article&category_new=__all__&module_name=Android_tt_others&share_did=MS4wLjACAAAAeVX-6RpCkMTHGH2iYzJRLvKVVP4bNGK32agfv6jvBzM&share_uid=MS4wLjABAAAAWH6YI1MY6xc9jZXrifkhTHsXyx7M_or_Vy6p0uwvq50×tamp=1784909906&tt_from=wechat&upstream_biz=Android_wechat&utm_campaign=client_share&utm_medium=toutiao_android&utm_source=wechat&share_token=83858a41-b370-4df9-9871-0617c3cc6cec&source=m_redirect
起点中文网: 魔修双穿浣熊市,炼百万血尸幡!
https://www.qidian.com/chapter/1048345068/891881253/
番茄: 赶山打猎:开局傻子,白捡个媳妇
https://fanqienovel.com/reader/7543148263973585433
https://www.toutiao.com/article/7660562749302292992/?app=news_article&category_new=__all__&module_name=Android_tt_others&share_did=MS4wLjACAAAAeVX-6RpCkMTHGH2iYzJRLvKVVP4bNGK32agfv6jvBzM&share_uid=MS4wLjABAAAAWH6YI1MY6xc9jZXrifkhTHsXyx7M_or_Vy6p0uwvq50×tamp=1784816031&tt_from=wechat&upstream_biz=Android_wechat&utm_campaign=client_share&utm_medium=toutiao_android&utm_source=wechat&share_token=24feb961-c48f-423e-a32a-5f6aa9641a65&source=m_redirect
DeepSeek V4免费渠道,实测能用,一分钱没花
https://www.toutiao.com/article/7664909891089236480/?app=news_article&category_new=text_inner_flow&module_name=Android_tt_others&share_did=MS4wLjACAAAAeVX-6RpCkMTHGH2iYzJRLvKVVP4bNGK32agfv6jvBzM&share_uid=MS4wLjABAAAAWH6YI1MY6xc9jZXrifkhTHsXyx7M_or_Vy6p0uwvq50×tamp=1784733607&tt_from=wechat&upstream_biz=Android_wechat&utm_campaign=client_share&utm_medium=toutiao_android&utm_source=wechat&share_token=2953795d-5e7a-4ce8-8789-dcc2bec53f60&source=m_redirect
16个ASR模型族、一个C++库:transcribe.cpp 把本地语音转录卷到新高度
https://www.toutiao.com/article/7664785505313980968/?app=news_article&category_new=__all__&module_name=Android_tt_others&share_did=MS4wLjACAAAAeVX-6RpCkMTHGH2iYzJRLvKVVP4bNGK32agfv6jvBzM&share_uid=MS4wLjABAAAAWH6YI1MY6xc9jZXrifkhTHsXyx7M_or_Vy6p0uwvq50×tamp=1784713136&tt_from=wechat&upstream_biz=Android_wechat&utm_campaign=client_share&utm_medium=toutiao_android&utm_source=wechat&share_token=2c2ff7c6-165c-439c-8617-3888fc6cedee&source=m_redirect
NLopt,一个开源的c++库
https://www.toutiao.com/article/7662503684458234368/?app=news_article&category_new=__all__&module_name=Android_tt_others&share_did=MS4wLjACAAAAeVX-6RpCkMTHGH2iYzJRLvKVVP4bNGK32agfv6jvBzM&share_uid=MS4wLjABAAAAWH6YI1MY6xc9jZXrifkhTHsXyx7M_or_Vy6p0uwvq50×tamp=1784561517&tt_from=wechat&upstream_biz=Android_wechat&utm_campaign=client_share&utm_medium=toutiao_android&utm_source=wechat&share_token=0c4ba8e6-888d-465a-a8d5-2cf7f510f317&source=m_redirect
每天 5 分钟看完全网热点
https://www.toutiao.com/w/1871116598260739/?app=news_article&category_new=text_inner_flow&module_name=Android_tt_others&share_did=MS4wLjACAAAAeVX-6RpCkMTHGH2iYzJRLvKVVP4bNGK32agfv6jvBzM&share_uid=MS4wLjABAAAAWH6YI1MY6xc9jZXrifkhTHsXyx7M_or_Vy6p0uwvq50×tamp=1784549941&tt_from=wechat&upstream_biz=Android_wechat&utm_campaign=client_share&utm_medium=toutiao_android&utm_source=wechat&share_token=e3968691-661f-48c5-bc76-eb08c792b33d&source=m_redirect
hermes免费体验deepseekV4( https://build.nvidia.com/ )
https://www.toutiao.com/article/7632486836014760488/?app=news_article&category_new=__all__&module_name=Android_tt_others&share_did=MS4wLjACAAAAeVX-6RpCkMTHGH2iYzJRLvKVVP4bNGK32agfv6jvBzM&share_uid=MS4wLjABAAAAWH6YI1MY6xc9jZXrifkhTHsXyx7M_or_Vy6p0uwvq50×tamp=1784028421&tt_from=wechat&upstream_biz=Android_wechat&utm_campaign=client_share&utm_medium=toutiao_android&utm_source=wechat&share_token=341f512f-c759-421a-acb4-0699f212182f&source=m_redirect
</LISTEXT>
$$task_template_file="{apl}/runyu/AI_code/AI_Code_apl/deepseek/auto_training/template/read_URL.txt";
$$task_template=read_text_file($$task_template_file,$bom);
if($bom!="utf-bom") { $task_template=to_utf8($task_template);}
foreach($$urls,$url)
{
APP::read_url $url;
sleep(1000*60);
}
getche("...");
function APP::read_url($url)
{
print_ln "begin read: "+$url[0];
$task=replace_sub_strings($$task_template,"{URL}", $url[1]);
$time=get_current_time($date);
$task=replace_sub_strings($task,"{今天日期}", to_string($date) );
$task=replace_sub_strings($task,"{当前时间}", to_string($time) );
write_text_file("{apl}/runyu/AI_code/AI_Code_apl/deepseek/auto_training/task.txt",$task,"utf8");
$cmd="python.exe " + "d:/apl/runyu/AI_code/AI_Code_apl/deepseek/auto_training/workbuddy_helper.py" ;
system $cmd;
print_ln "end read";
}