mcpField
S
shortcuts-generator

shortcuts-generator

github.com/drewocarr生产力21962 次安装41 周前更新
代码仓库

关于 shortcuts-generator

用于生成可签名并导入 Apple Shortcuts 的 `.shortcut` 文件的技能。它提供 plist 结构、动作参数、变量引用和控制流的参考,适合构建自动化快捷指令。

主要功能

  1. 01生成快捷指令 plist 文件
  2. 02配置动作标识符与参数
  3. 03连接动作输出和变量引用
  4. 04构建重复、条件和菜单控制流
  5. 05提供动作与参数参考

适用场景

  1. 01创建包含多个动作的快捷指令
  2. 02将前一步输出传入后续动作
  3. 03构建含条件或重复步骤的流程
  4. 04签名文件后导入 Shortcuts

安装

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

$npx skills add https://github.com/drewocarr/generate-shortcuts-skill --skill shortcuts-generator

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

包含的文件

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

APPINTENTS.md
README.md
ACTIONS.md
PLIST_FORMAT.md
VARIABLES.md
CONTROL_FLOW.md
EXAMPLES.md
FILTERS.md
PARAMETER_TYPES.md

详细介绍

macOS 快捷指令生成器

生成有效的 .shortcut 文件,这些文件可以签名并导入 Apple 的快捷指令应用。

快速开始

快捷指令是一个二进制 plist,具有以下结构:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>WFWorkflowActions</key>
    <array>
        
    </array>
    <key>WFWorkflowClientVersion</key>
    <string>2700.0.4</string>
    <key>WFWorkflowHasOutputFallback</key>
    <false/>
    <key>WFWorkflowIcon</key>
    <dict>
        <key>WFWorkflowIconGlyphNumber</key>
        <integer>59511</integer>
        <key>WFWorkflowIconStartColor</key>
        <integer>4282601983</integer>
    </dict>
    <key>WFWorkflowImportQuestions</key>
    <array/>
    <key>WFWorkflowMinimumClientVersion</key>
    <integer>900</integer>
    <key>WFWorkflowMinimumClientVersionString</key>
    <string>900</string>
    <key>WFWorkflowName</key>
    <string>My Shortcut</string>
    <key>WFWorkflowOutputContentItemClasses</key>
    <array/>
    <key>WFWorkflowTypes</key>
    <array/>
</dict>
</plist>
最简 Hello World
<dict>
    <key>WFWorkflowActionIdentifier</key>
    <string>is.workflow.actions.gettext</string>
    <key>WFWorkflowActionParameters</key>
    <dict>
        <key>UUID</key>
        <string>A1B2C3D4-E5F6-7890-ABCD-EF1234567890</string>
        <key>WFTextActionText</key>
        <string>Hello World!</string>
    </dict>
</dict>
<dict>
    <key>WFWorkflowActionIdentifier</key>
    <string>is.workflow.actions.showresult</string>
    <key>WFWorkflowActionParameters</key>
    <dict>
        <key>Text</key>
        <dict>
            <key>Value</key>
            <dict>
                <key>attachmentsByRange</key>
                <dict>
                    <key>{0, 1}</key>
                    <dict>
                        <key>OutputName</key>
                        <string>Text</string>
                        <key>OutputUUID</key>
                        <string>A1B2C3D4-E5F6-7890-ABCD-EF1234567890</string>
                        <key>Type</key>
                        <string>ActionOutput</string>
                    </dict>
                </dict>
                <key>string</key>
                <string></string>
            </dict>
            <key>WFSerializationType</key>
            <string>WFTextTokenString</string>
        </dict>
    </dict>
</dict>

核心概念

1. 操作

每个操作都包含:

  • 标识符:is.workflow.actions.<name>(例如,is.workflow.actions.showresult)
  • 参数:在 WFWorkflowActionParameters 中配置的操作专属设置
  • UUID:用于引用此操作输出的唯一标识符
2. 变量引用

要使用前一个操作的输出:

  1. 源操作需要一个 UUID 参数
  2. 在 attachmentsByRange 字典中使用 OutputUUID 引用它
  3. 在字符串中变量所在的位置使用 (U+FFFC)作为占位符
  4. 将 WFSerializationType 设置为 WFTextTokenString
3. 控制流

控制流操作(重复、条件、菜单)使用:

  • GroupingIdentifier:用于关联开始/中间/结束操作的 UUID
  • WFControlFlowMode:0=开始,1=中间(否则/分支),2=结束

常见操作速查

操作标识符关键参数
文本is.workflow.actions.gettextWFTextActionText
显示结果is.workflow.actions.showresultText
询问输入is.workflow.actions.askWFAskActionPrompt、WFInputType
使用 AI 模型is.workflow.actions.askllmWFLLMPrompt、WFLLMModel、WFGenerativeResultType
注释is.workflow.actions.commentWFCommentActionText
URLis.workflow.actions.urlWFURLActionURL
获取 URL 内容is.workflow.actions.downloadurlWFURL、WFHTTPMethod
获取天气is.workflow.actions.weather.currentconditions(无需参数)
打开应用is.workflow.actions.openappWFAppIdentifier
打开 URLis.workflow.actions.openurlWFInput
提醒is.workflow.actions.alertWFAlertActionTitle、WFAlertActionMessage
通知is.workflow.actions.notificationWFNotificationActionTitle、WFNotificationActionBody
设置变量is.workflow.actions.setvariableWFVariableName、WFInput
获取变量is.workflow.actions.getvariableWFVariable
数字is.workflow.actions.numberWFNumberActionNumber
列表is.workflow.actions.listWFItems
词典is.workflow.actions.dictionaryWFItems
重复(次数)is.workflow.actions.repeat.countWFRepeatCount、GroupingIdentifier、WFControlFlowMode
重复(对每一项)is.workflow.actions.repeat.eachWFInput、GroupingIdentifier、WFControlFlowMode
如果/否则is.workflow.actions.conditionalWFInput、WFCondition、GroupingIdentifier、WFControlFlowMode
从菜单中选取is.workflow.actions.choosefrommenuWFMenuPrompt、WFMenuItems、GroupingIdentifier、WFControlFlowMode
查找照片is.workflow.actions.filter.photosWFContentItemFilter(参见 FILTERS.md)
删除照片is.workflow.actions.deletephotosphotos(不是 WFInput!)

详细参考文件

完整文档请参见:

签名快捷指令

快捷指令必须先签名才能导入。使用 macOS shortcuts CLI:

# Sign for anyone to use
shortcuts sign --mode anyone --input MyShortcut.shortcut --output MyShortcut_signed.shortcut

# Sign for people who know you
shortcuts sign --mode people-who-know-me --input MyShortcut.shortcut --output MyShortcut_signed.shortcut

签名流程:

  1. 将 plist 写为 XML 并保存到 .shortcut 文件
  2. 运行 shortcuts sign 以添加加密签名(约增加 19KB)
  3. 签名后的文件可在 Shortcuts.app 中打开/导入

创建快捷指令的工作流

  1. 定义操作 - 列出快捷指令应执行的操作
  2. 生成 UUID - 每个会产生输出的操作都需要唯一的 UUID
  3. 构建操作数组 - 为每个操作创建包含标识符和参数的字典
  4. 连接变量引用 - 使用 OutputUUID 将输出连接到输入
  5. 封装为 plist - 添加包含图标、名称和版本的根结构
  6. 写入文件 - 保存为 .shortcut(XML plist 格式即可)
  7. 签名 - 运行 shortcuts sign 使其可导入

关键规则

  1. UUID 必须为大写:A1B2C3D4-E5F6-7890-ABCD-EF1234567890
  2. WFControlFlowMode 是整数:使用 <integer>0</integer>,而不是 <string>0</string>
  3. 范围键的格式为:{position, length} - 例如,{0, 1} 表示第一个字符
  4. 占位符字符:(U+FFFC)标记变量插入的位置
  5. 控制流需要匹配的结束操作:每个重复/条件/菜单起始操作都需要一个具有相同 GroupingIdentifier 的结束操作

评论

支持 Markdown