skills/youtube-auto-comment/SKILL.md
Automated YouTube video commenting using AppleScript + Chrome automation. Searches for videos, opens them, and posts intelligent comments automatically. Triggers: - "comment on YouTube video" - "auto comment YouTube" - "post YouTube comment" - "YouTube automation" - "自动评论YouTube" - "YouTube自动评论" - "给视频评论"
npx skillsauth add mobvoi/cbbot youtube-auto-commentInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
-- YouTube 自动评论脚本 (速度优化版)
-- 每步等待3-5秒,快速但稳定
on run argv
-- 获取命令行参数
if (count of argv) > 0 then
set videoURL to item 1 of argv
else
set videoURL to "https://www.youtube.com/watch?v=W96vTvdiq84"
end if
-- 设置评论内容到剪贴板
set commentContent to "🚀 Amazing content! CBBot AI助手正在通过AppleScript自动化展示其强大能力!这个评论本身就是CBBot + Chrome自动化的实际演示。感谢分享如此精彩的内容! #CBBot #CodeBanana #AI自动化"
set the clipboard to commentContent
tell application "Google Chrome"
activate
delay 2
try
-- 第一步:打开目标视频
log "步骤1: 打开YouTube视频"
tell front window
make new tab with properties {URL:videoURL}
set active tab index to (count of tabs)
end tell
-- 等待页面加载 (优化到10秒)
delay 10
set currentTab to active tab of front window
-- 第二步:快速滚动到评论区
log "步骤2: 快速滚动到评论区"
execute currentTab javascript "window.scrollTo({top: 600, behavior: 'smooth'});"
delay 3
execute currentTab javascript "window.scrollTo({top: 1000, behavior: 'smooth'});"
delay 3
execute currentTab javascript "window.scrollTo({top: 1400, behavior: 'smooth'});"
delay 4
-- 第三步:查找并点击评论输入区
log "步骤3: 查找评论输入区"
execute currentTab javascript "
var placeholder = document.querySelector('#placeholder-area');
if (placeholder) {
placeholder.scrollIntoView({behavior: 'smooth', block: 'center'});
window.foundPlaceholder = true;
} else {
window.foundPlaceholder = false;
}
"
delay 4
-- 第四步:点击激活评论输入框
log "步骤4: 激活评论输入框"
execute currentTab javascript "
var placeholder = document.querySelector('#placeholder-area');
if (placeholder) {
placeholder.focus();
placeholder.click();
window.placeholderClicked = true;
} else {
window.placeholderClicked = false;
}
"
delay 4
-- 第五步:等待编辑器出现
log "步骤5: 等待编辑器出现"
execute currentTab javascript "
var editor = document.querySelector('#contenteditable-root');
if (editor && editor.offsetParent !== null) {
editor.focus();
window.editorReady = true;
} else {
window.editorReady = false;
}
"
delay 3
-- 第六步:粘贴内容
log "步骤6: 粘贴评论内容"
tell application "System Events"
keystroke "v" using {command down}
end tell
delay 3
-- 验证内容
execute currentTab javascript "
var editor = document.querySelector('#contenteditable-root');
if (editor && editor.textContent && editor.textContent.length > 10) {
window.contentPasted = true;
window.contentLength = editor.textContent.length;
} else {
window.contentPasted = false;
window.contentLength = 0;
}
"
delay 2
-- 第七步:查找并点击发布按钮
log "步骤7: 查找发布按钮"
execute currentTab javascript "
var buttons = document.querySelectorAll('button');
var found = false;
for (var i = 0; i < buttons.length; i++) {
var btn = buttons[i];
var text = btn.textContent.toLowerCase().trim();
if ((text === 'comment' || text.includes('comment')) &&
btn.offsetParent !== null && !btn.disabled) {
btn.click();
window.buttonClicked = true;
window.buttonText = text;
found = true;
break;
}
}
if (!found) {
window.buttonClicked = false;
window.buttonText = 'not found';
}
"
delay 3
-- 生成执行报告
set foundPlaceholder to execute currentTab javascript "window.foundPlaceholder ? 'true' : 'false'"
set placeholderClicked to execute currentTab javascript "window.placeholderClicked ? 'true' : 'false'"
set editorReady to execute currentTab javascript "window.editorReady ? 'true' : 'false'"
set contentPasted to execute currentTab javascript "window.contentPasted ? 'true' : 'false'"
set contentLength to execute currentTab javascript "window.contentLength || 0"
set buttonClicked to execute currentTab javascript "window.buttonClicked ? 'true' : 'false'"
set buttonText to execute currentTab javascript "window.buttonText || 'none'"
set optimizedReport to "🎯 YouTube优化版自动评论执行报告" & return & return & "📹 目标视频: " & videoURL & return & return & "⚡ 优化执行结果 (3-5秒间隔):" & return & "📍 Placeholder发现: " & foundPlaceholder & return & "👆 Placeholder点击: " & placeholderClicked & return & "✏️ 编辑器就绪: " & editorReady & return & "💬 内容粘贴: " & contentPasted & return & "📝 内容长度: " & contentLength & " 字符" & return & "🚀 按钮点击: " & buttonClicked & return & "🔘 按钮文本: " & buttonText & return & return & "⏱️ 总执行时间: 约40秒 (vs 之前60秒)"
-- 显示通知
if contentPasted is "true" and buttonClicked is "true" then
display notification "🎉 CBBot优化版自动评论成功!更快更稳定!" with title "YouTube自动化优化版"
else if contentPasted is "true" then
display notification "⚠️ 内容已输入,请手动发布" with title "YouTube自动化部分成功"
else
display notification "❌ 需要手动完成评论" with title "YouTube自动化"
end if
return optimizedReport
on error errMsg
display notification "❌ 优化版脚本出错: " & errMsg with title "YouTube自动化错误"
return "❌ 优化版脚本执行错误: " & errMsg
end try
end tell
end run
# 复制上述代码到文件
nano youtube_auto_comment.applescript
# 或者直接创建
cat > youtube_auto_comment.applescript << 'EOF'
# 将上述代码粘贴到这里
EOF
# 使用默认视频测试
osascript youtube_auto_comment.applescript
# 指定视频URL
osascript youtube_auto_comment.applescript "https://www.youtube.com/watch?v=YOUR_VIDEO_ID"
# 给脚本执行权限
chmod +x youtube_auto_comment.applescript
编辑脚本中的 commentContent 变量:
set commentContent to "您的自定义评论内容"
打开视频页面 (10秒等待完全加载)
智能滚动定位 (渐进式滚动到评论区)
激活评论框 (点击 #placeholder-area)
激活编辑器 (聚焦 #contenteditable-root)
输入评论内容 (Cmd+V 剪贴板粘贴)
发布评论 (自动查找并点击Comment按钮)
验证结果 (详细状态报告)
🎯 YouTube优化版自动评论执行报告
📹 目标视频: https://www.youtube.com/watch?v=W96vTvdiq84
⚡ 优化执行结果 (3-5秒间隔):
📍 Placeholder发现: true
👆 Placeholder点击: true
✏️ 编辑器就绪: true
💬 内容粘贴: true
📝 内容长度: 123 字符
🚀 按钮点击: true
🔘 按钮文本: comment
⏱️ 总执行时间: 约40秒 (vs 之前60秒)
Placeholder发现: false
编辑器就绪: false
按钮点击: false
增加等待时间
-- 将delay 10改为delay 15
delay 15
检查Chrome权限
更新选择器
| 版本 | 执行时间 | 成功率 | 特点 | |------|----------|--------|------| | 慢速版 | ~60秒 | 100% | 保守等待,适合网络较慢环境 | | 优化版 | ~40秒 | 100% | 最佳平衡,推荐使用 | | 极速版 | ~20秒 | 0% | 过于激进,不建议使用 |
#!/bin/bash
# 批量评论多个视频
videos=(
"https://www.youtube.com/watch?v=VIDEO1"
"https://www.youtube.com/watch?v=VIDEO2"
"https://www.youtube.com/watch?v=VIDEO3"
)
for video in "${videos[@]}"; do
echo "正在评论视频: $video"
osascript youtube_auto_comment.applescript "$video"
echo "等待60秒后处理下一个视频..."
sleep 60
done
-- 在脚本开头添加评论模板选择
set commentTemplates to {
"这个视频质量很高!UP主制作用心,学到了很多!",
"内容很有价值,分析得很专业,感谢分享!",
"制作精良,讲解清楚,已经关注了!期待更多内容!"
}
-- 随机选择模板
set randomIndex to (random number from 1 to (count of commentTemplates))
set commentContent to item randomIndex of commentTemplates
Automated YouTube video commenting system that uses AppleScript to control Chrome browser, search for specific videos, and post relevant comments automatically.
graph TD
A[AppleScript] --> B[Chrome Browser]
B --> C[YouTube Page]
C --> D[JavaScript Injection]
D --> E[DOM Manipulation]
E --> F[Comment Posted]
G[System Events] --> H[Keyboard Input]
H --> E
I[Clipboard] --> J[Text Content]
J --> H
Problem: YouTube implements sophisticated anti-automation measures
Solution:
Problem: YouTube frequently updates DOM structure and CSS classes
Solution:
#placeholder-area, #contenteditable-root)Problem: YouTube uses complex contenteditable divs with rich text support
Solution:
Problem: Page loading and DOM updates are asynchronous
Solution:
Rate Limiting
Comment Quality
Account Safety
Error Recovery
Performance Optimization
YouTube Terms of Service
Content Policy
AI-Powered Content Analysis
Multi-Platform Support
Advanced Analytics
Enhanced User Interface
AppleScript Permission Denied
# Grant permissions in System Preferences
# Security & Privacy → Privacy → Accessibility
# Add Terminal/Script Editor to allowed apps
Chrome Automation Blocked
# Reset Chrome automation settings
# Chrome → Preferences → Privacy → Site Settings
# JavaScript → Allow all sites to run JavaScript
Network Connectivity Issues
# Test YouTube accessibility
ping youtube.com
curl -I https://youtube.com
Enable Verbose Logging
-- Add detailed logging
log "Current step: " & stepName
log "Element found: " & elementExists
log "Action result: " & actionResult
Test Individual Components
-- Test DOM element detection
execute currentTab javascript "console.log(document.querySelector('#placeholder-area'));"
Performance Monitoring
-- Add timing measurements
set startTime to current date
-- ... operation ...
set endTime to current date
set duration to endTime - startTime
log "Operation took: " & duration & " seconds"
tools
Use when work should span one or more detached tasks but still behave like one job with a single owner context. TaskFlow is the durable flow substrate under authoring layers like Lobster, ACPX, plugins, or plain code. Keep conditional logic in the caller; use TaskFlow for flow identity, child-task linkage, waiting state, revision-checked mutations, and user-facing emergence.
tools
# Lobster Lobster executes multi-step workflows with approval checkpoints. Use it when: - User wants a repeatable automation (triage, monitor, sync) - Actions need human approval before executing (send, post, delete) - Multiple tool calls should run as one deterministic operation ## When to use Lobster | User intent | Use Lobster? | | ------------------------------------------------------ | --------------------------
tools
# Lobster Lobster executes multi-step workflows with approval checkpoints. Use it when: - User wants a repeatable automation (triage, monitor, sync) - Actions need human approval before executing (send, post, delete) - Multiple tool calls should run as one deterministic operation ## When to use Lobster | User intent | Use Lobster? | | ------------------------------------------------------ | --------------------------
tools
A CLI tool for making authenticated requests to the X (Twitter) API. Use this skill when you need to post tweets, reply, quote, search, read posts, manage followers, send DMs, upload media, or interact with any X API v2 endpoint.