mcpField
A
automating-keynote

automating-keynote

github.com/spillwavesolutions文档处理48114 次安装10 周前更新
代码仓库

关于 automating-keynote

这是一项面向 Keynote 的 macOS 自动化技能,适合编写和维护演示文稿脚本。它以 JXA 为主,结合 AppleScript 探索对象模型,并介绍幻灯片、图片和导出等操作。

主要功能

  1. 01用 JXA 自动化 Keynote
  2. 02通过 AppleScript 探索对象模型
  3. 03创建幻灯片并设置母版
  4. 04添加图片并指定文件路径
  5. 05查阅图表与导出操作指南

适用场景

  1. 01读取 Keynote 文稿信息
  2. 02脚本化创建演示文稿页面
  3. 03向幻灯片插入图片
  4. 04验证演示文稿导出流程

安装

复制下面的命令,在终端中运行。

$npx skills add https://github.com/spillwavesolutions/automating-mac-apps-plugin --skill automating-keynote

安装后在 Claude Code 中输入/automating-keynote确认已加载。

包含的文件

除 SKILL.md 外,安装时一起下载的参考资料和脚本。

references/
keynote-advanced.md
keynote-basics.md
keynote-chart-aware-deck.md
keynote-deck-generator.md
keynote-pyxa-api-reference.md
keynote-pyxa.md
keynote-recipes.md
scripts/
create_keynote_presentation.py
create_presentation.js
export_keynote_presentation.py
markdown_to_keynote.py
set_up_keynote_automation.py
set_up_keynote_automation.sh

详细介绍

自动化 Keynote(以 JXA 为主,探索 AppleScript)

目录

与 macOS 自动化技能的关系

  • 此技能专注于 Keynote 特定的自动化(文稿、幻灯片、图表)。
  • 对于跨应用工作流或通用 macOS 脚本基础,请使用 automating-mac-apps。
  • 假定你已掌握相关技能中的 Apple Events 知识。
  • **PyXA 安装:**如需在此技能中使用 PyXA 示例,请参阅 automating-mac-apps 技能中的安装说明(PyXA 安装部分)。

核心思路

  • JXA(JavaScript for Automation)支持使用 JavaScript 语法编写 macOS 应用脚本。
  • AppleScript 词典定义了 Keynote 的对象模型,可通过脚本编辑器探索。
  • JXA 对象是说明符:使用 .name() 等方法读取,通过赋值进行写入。
  • 生产脚本使用 JXA 来确保可靠性;原型开发则使用 AppleScript。
  • **重要:**指定 Keynote 的文件路径时(例如用于图像、导出或打开文稿),必须使用 JXA 的 Path() 函数。请使用 Path("/path/to/file"),不要使用普通字符串。

工作流(默认)

  1. 在脚本编辑器中依次选择“文件”>“打开词典”>“Keynote”,查找相关术语。
  2. 编写最简 AppleScript 原型:tell application "Keynote" to get name of document 1。
  3. 移植到 JXA:Application("Keynote").documents[0].name(),并添加 try-catch 块。
  4. 使用只读探测进行验证:Application("Keynote").documents.length > 0。
  5. 仅在词典缺少相应功能时使用 UI 脚本(例如 Application("System Events"))。

快速示例

原型(AppleScript):

tell application "Keynote"
    get name of document 1
end tell

生产环境(JXA):

const keynote = Application("Keynote");
if (keynote.documents.length > 0) {
    console.log(keynote.documents[0].name());
}

创建幻灯片:

const doc = keynote.documents[0];
const slide = doc.slides.push(keynote.Slide({baseSlide: doc.masterSlides['Title - Center']}));
slide.defaultTitleItem.objectText = "New Slide";

向幻灯片添加图像(注意使用 Path()):

const slide = doc.slides[0];
const img = keynote.Image({
  file: Path("/Users/you/Desktop/diagram.png"),  // Path() required!
  position: { x: 100, y: 100 },
  width: 800
});
slide.images.push(img);

验证清单

实现 Keynote 自动化后:

  • 确认 Keynote 正在运行且可访问
  • 测试创建幻灯片时是否分配了母版幻灯片
  • 确认图像路径使用 Path() 函数
  • 检查默认文本项中的文本渲染效果
  • 确认导出操作完成且没有错误

不适用场景

  • 跨平台演示文稿自动化(请使用带 Python 库的 PowerPoint)
  • AppleScript 已能满足需求(无需增加 JXA 的复杂性)
  • 基于 Web 的演示文稿(Google Slides、reveal.js)
  • 非 macOS 平台

需要加载的内容

  • Keynote JXA 基础知识和运行时注意事项:automating-keynote/references/keynote-basics.md
  • Keynote 操作示例(幻灯片、文本、图像、导出):automating-keynote/references/keynote-recipes.md
  • 演示文稿生成器示例:automating-keynote/references/keynote-deck-generator.md
  • 支持图表的演示文稿模式:automating-keynote/references/keynote-chart-aware-deck.md
  • 高级工作流(图表桥接、神奇移动、UI 脚本):automating-keynote/references/keynote-advanced.md
  • PyXA(Python)实用示例:automating-keynote/references/keynote-pyxa.md
  • PyXA API 参考(完整的类和方法文档):automating-keynote/references/keynote-pyxa-api-reference.md

评论

支持 Markdown