Capture screenshots on macOS with built-in tools only.
screencapture -x <output>.owner and name, matching keywords like weixin, wechat, or the app name the user gave.sharing is 1.screencapture -x -l <windowId> <output>.Prefer the bundled script when available:
bash
scripts/capture-window-by-keyword.sh <keyword> [output_path]
scripts/capture-window-by-keyword.sh --list <keyword>
scripts/capture-window-by-keyword.sh --index <n> <keyword> [output_path]
Examples:
bash
scripts/capture-window-by-keyword.sh wechat
scripts/capture-window-by-keyword.sh --list wechat
scripts/capture-window-by-keyword.sh --index 2 wechat
The script:
owner and nameweixin -> wechat, wxsharing = 1screencapture -x -l <windowId>Use this exact pattern to locate candidate windows:
bash
swift - <<'SWIFT'
import CoreGraphics
import Foundation
let options = CGWindowListOption(arrayLiteral: .optionOnScreenOnly, .excludeDesktopElements)
let windows = (CGWindowListCopyWindowInfo(options, kCGNullWindowID) as? [[String: Any]]) ?? []
let matches = windows.compactMap { w -> [String: Any]? in
let owner = (w[kCGWindowOwnerName as String] as? String) ?? ""
let name = (w[kCGWindowName as String] as? String) ?? ""
let low = (owner + " " + name).lowercased()
guard low.contains("weixin") || low.contains("wechat") else { return nil }
return [
"id": w[kCGWindowNumber as String] ?? "",
"owner": owner,
"name": name,
"sharing": w[kCGWindowSharingState as String] ?? "",
"bounds": w[kCGWindowBounds as String] ?? ""
]
}
let data = try! JSONSerialization.data(withJSONObject: matches, options: [.prettyPrinted])
print(String(data: data, encoding: .utf8)!)
SWIFT
Typical success indicators:
owner or name matches the requested app/windowid is presentsharing = 1Then capture the window:
bash
screencapture -x -l <windowId> <output.png>
Quartz; it may not be installed.System Events window attributes for window IDs; some apps do not expose AXWindowNumber reliably.CGWindowListCopyWindowInfo is the most reliable built-in approach on macOS.screencapture -l <windowId> is a true system window capture, not a cropped full-screen image.screencapture works for full screen but not for a window#Check whether the enumerated target has sharing = 1. If not, tell the user the app/window is not currently shareable for window capture and ask them to bring it to the front and try again.
System Events says assistive access is not allowed#Do not rely on that path. Prefer the Swift + CoreGraphics method. If the user still wants UI-structure inspection, tell them to enable:
openclaw-gateway, Terminal, or the active terminal hostTell the user to enable:
swift is not found#Tell the user to install Xcode Command Line Tools manually:
bash
xcode-select --install
If that fails or they want the GUI path, tell them to install Xcode from the App Store or re-run the command after opening Software Update.
Prefer saving screenshots into a workspace subdirectory like:
screenshots/captures/Use descriptive filenames with timestamps when the user may request multiple captures.
Treat screenshots as potentially sensitive local artifacts.
When a screenshot request comes from a chat surface: