这是一个面向 macOS 的 Keynote 自动化技能,核心是用 JXA(JavaScript for Automation)驱动 Apple Keynote,通过 AppleScript 字典发现 Keynote 的对象模型,实现文档、幻灯片和图表等操作。
主要能力包括:创建演示文稿与幻灯片、按母版幻灯片添加页面、设置标题文本、插入图片以及执行导出等。JXA 对象为 specifier,读取用 .name() 一类方法,写入用赋值;生产脚本推荐用 JXA 以保证可靠性,AppleScript 适合快速原型。
默认工作流:在脚本编辑器中选择“文件 > 打开字典 > Keynote”查看术语;先用最小 AppleScript 验证,如 tell application "Keynote" to get name of document 1;再移植为 JXA,例如 Application("Keynote").documents[0].name(),并加 try-catch;用只读探针校验,如 Application("Keynote").documents.length > 0;字典不支持的功能才使用 UI 脚本(System Events)。
指定文件路径给 Keynote 时必须使用 Path(),例如 Path("/path/to/file"),不能直接用字符串。若需使用 PyXA(Python)示例,安装方式见 automating-mac-apps 技能中的 PyXA Installation 部分。
适用场景为 macOS 上批量生成或修改 Keynote 演示文稿。限制:不适合跨平台演示自动化(可改用 PowerPoint 与 Python 库)、纯 AppleScript 已够用时不必引入 JXA、不适用于 Google Slides 或 reveal.js 等网页演示,也不支持非 macOS 平台。跨应用或通用 macOS 脚本基础应使用 automating-mac-apps 技能。