# macOS Chrome AppleScript — 飞书页面数据提取

当 MCP `search_view_by_title` 查不到视图时，直接用 Chrome 提取页面 view_id。

## 前置条件
Chrome → 查看 → 开发者 → **允许 Apple 事件中的 JavaScript**（一次性）

## 提取视图 view_id（本次攻克的关键模式）

```bash
# Step 1: 导航到飞书空间页面
osascript -e 'tell application "Google Chrome" to open location "https://project.feishu.cn/br-shgl/"'
sleep 5

# Step 2: 提取 visible text（查看有哪些视图链接）
osascript -e '
tell application "Google Chrome"
  set js to "document.body.innerText.substring(0, 3000)"
  set result to execute front window'"'"'s active tab javascript js
  return result
end tell'
# 输出: ...客诉视图V01_副本\n客诉视图V01...

# Step 3: 点击视图链接（找到元素并click）
osascript -e '
tell application "Google Chrome"
  set js to "
  var links = document.querySelectorAll('"'"'*'"'"');
  links.forEach(function(el) {
    if (el.innerText === '"'"'客诉视图V01'"'"' && el.children.length === 0) el.click();
  });
  "
  set result to execute front window'"'"'s active tab javascript js
end tell'

# Step 4: 提取view_id
osascript -e '
tell application "Google Chrome"
  set js to "window.location.href"
  set result to execute front window'"'"'s active tab javascript js
end tell'
# → https://project.feishu.cn/br-shgl/workObjectView/khts/TDWUJhYHg?scope=workspaces&node=...
# → view_id = "TDWUJhYHg"
```

## 飞书页面限制

- **虚拟表格**（决策链视图）：无标准 `<table>`，innerText 可读但截断
- **Wiki画板**：Canvas内容无法DOM提取
- **screencapture**：Chrome窗口截图返回错误

## 替代优先级
1. MCP MQL WHERE精确匹配
2. MCP `list_related_workitem` + relation_id
3. 用户导出CSV（最可靠）
4. Chrome AppleScript（仅适用于导航+view_id提取）
