跳到正文

宝玉:X 图文与文章发布

组织 X 推文、媒体和长文,通过浏览器处理编辑与发布,实际提交需要用户明确授权。

开源精选内容生产20 个文件26,681 Stars浏览次数 0JimLiu/baoyu-skills MIT版本 1567581
开始使用

下载前阅读 SKILL.md 中的使用条件,并确认所用工具支持对应能力。

输入资料
确认后的推文或文章 账号和发布权限 阅读本节完整说明
交付内容
X 内容资料 实际发布结果 阅读本节完整说明
环境与依赖
Google Chrome or Chromium bun runtime First run: log in to X manually (session saved) 阅读本节完整说明
  1. 获取完整包,保留配套文件的目录结构。
  2. 按照原文准备所需工具、依赖与输入资料。
  3. 阅读对应使用步骤与输入输出说明,在自己的环境中验证结果。

使用提示摘自原文,配套文件保留来源版本;实际运行条件以各包说明为准。

正文

获取原文件

references/regular-posts.md

Detailed documentation for posting text and images to X.

Manual Workflow

If you prefer step-by-step control:

Step 0: Prefer Chrome Computer Use in Codex

When running inside Codex, first detect whether Chrome Computer Use is enabled:

  1. If Computer Use tools are already visible, call get_app_state for Google Chrome.
  2. If not, use tool_search for computer-use get_app_state click press_key drag scroll Google Chrome, then call get_app_state.
  3. If get_app_state succeeds, use the user's real Chrome with Computer Use for all X UI actions.
  4. Use CDP scripts only when Computer Use is unavailable or explicitly requested.

If the user explicitly asks for Chrome Computer Use, do not use Playwright, the in-app Browser, or CDP without approval.

Step 1: Copy Image to Clipboard

${BUN_X} {baseDir}/scripts/copy-to-clipboard.ts image /path/to/image.png

Step 2: Paste from Clipboard

# Simple paste to frontmost app
${BUN_X} {baseDir}/scripts/paste-from-clipboard.ts

# Paste to Chrome with retries
${BUN_X} {baseDir}/scripts/paste-from-clipboard.ts --app "Google Chrome" --retries 5

# Quick paste with shorter delay
${BUN_X} {baseDir}/scripts/paste-from-clipboard.ts --delay 200

Step 3: Use Chrome Computer Use (Preferred)

  1. Use get_app_state for Google Chrome.
  2. Navigate Chrome to https://x.com/compose/post if needed.
  3. Click the composer and type the post text.
  4. Copy each image to the clipboard with copy-to-clipboard.ts image <path>.
  5. Press super+v on macOS or control+v on Windows/Linux with Computer Use.
  6. Wait until X finishes media upload.
  7. Ask for explicit confirmation before clicking Post.

Image Support

  • Formats: PNG, JPEG, GIF, WebP
  • Max 4 images per post
  • Images copied to system clipboard, then pasted via keyboard shortcut

Example Session

User: /post-to-x "Hello from Claude!" --image ./screenshot.png

Claude:
1. Detects Chrome Computer Use
2. Opens X compose in the user's real Chrome
3. Types text into editor
4. Copies image to clipboard and pastes with Computer Use
5. Waits for upload and verifies the preview
6. Asks before clicking Post

Troubleshooting

  • Chrome not found: Set X_BROWSER_CHROME_PATH environment variable
  • Not logged in: First run opens Chrome - log in manually, cookies are saved
  • Image paste fails:
    • Verify clipboard script: ${BUN_X} {baseDir}/scripts/copy-to-clipboard.ts image <path>
    • On macOS, grant "Accessibility" permission to Terminal/iTerm in System Settings > Privacy & Security > Accessibility
    • Keep Chrome window visible and in front during paste operations
  • osascript permission denied: Grant Terminal accessibility permissions in System Preferences
  • Rate limited: Wait a few minutes before retrying

How It Works

In Chrome Computer Use mode:

  1. Codex controls the user's visible Google Chrome window
  2. Text is typed through the real UI
  3. Images are copied to the system clipboard and pasted with real keystrokes
  4. The user confirms before the final public post

The x-browser.ts script is the CDP fallback. It uses Chrome DevTools Protocol (CDP) to:

  1. Launch real Chrome (not Playwright) with --disable-blink-features=AutomationControlled
  2. Use persistent profile directory for saved login sessions
  3. Interact with X via CDP commands (Runtime.evaluate, Input.dispatchKeyEvent)
  4. Paste images using osascript (macOS): Sends real Cmd+V keystroke to Chrome, bypassing CDP's synthetic events that X can detect

This approach bypasses X's anti-automation detection that blocks Playwright/Puppeteer.

Image Paste Mechanism (macOS)

CDP's Input.dispatchKeyEvent sends "synthetic" keyboard events that websites can detect. X ignores synthetic paste events for security. The solution:

  1. Copy image to system clipboard via Swift/AppKit (copy-to-clipboard.ts)
  2. Bring Chrome to front via osascript
  3. Send real Cmd+V keystroke via osascript and System Events
  4. Wait for upload to complete

This requires Terminal to have "Accessibility" permission in System Settings.

CONTACT HAONAN

联系haonan

医疗 AI · 产品与独立开发

刘浩南

关注医疗 AI 从 demo 到真实落地,聚焦产品化、商业化与院内工作流效率提升。

12年医疗产研经验,大湾区头部医疗AI公司前产品总监,独立开发者

医疗 AI 产品化医疗 AI 商业化院内工作流效率
刘浩南的微信联系二维码
微信扫一扫,联系 haonan