# Keyboard Maestro简介

***

![](https://cdn.jsdelivr.net/gh/wuzimuws/imgbed@main/img/202403142355982.png)

Keyboard Maestro 也许是适用于 Mac 的最强大的自动化工具。

最重要的是，任何人都可以简单上手。&#x20;

Keyboard Maestro 不依赖于脚本语言，只需要设置好 「触发器 Trigger」 和 「动作 Action」 ，即可制作出满足需求的宏。

### 逻辑简单🥳

任务自动化的逻辑非常简单，只需要三步：

1. [拆解任务](/chai-jie-ren-wu-de-fang-fa.md)
2. 选择[触发器（Trigger）](/chu-fa-qi-trigger.md)
3. 设置[动作（Action）](/dong-zuo-action.md)

![任务自动化的逻辑](https://cdn.jsdelivr.net/gh/wuzimuws/imgbed@main/img/202403171141419.png)

### 快速上手！

我们以一个简单示例来实践一下Keyboard Maestro的自动化逻辑。

> **场景示例：日常工作中时常会遇到需要保存的文本，而这些文本都需要保存到指定文本文件中。**

平时遇到上述场景，我们通常要重复进行以下动作：

> 1. 先想好：文本要保存到何处，目标文本文档的存储位置在哪？
> 2. 在访达（Finder）中找到文本文档的存储位置，打开文档。
> 3. 执行复制、粘贴操作，进行保存。

➀ 首先，我们对任务进行拆解，根据[拆解任务](/chai-jie-ren-wu-de-fang-fa.md)的逻辑，我们可以得出，该任务属于「重复无交互式任务」，即：

* 在任务中无需引入其他类型的变量，待复制文本只需要通过复制粘贴命令即可实现（重复性任务）
* 目标存储文本文档确定，存储位置确定（重复性任务）
* 不需要根据用户的指令来确定任务走向，即无需进行交互（无交互式任务）

➁ 然后选择触发器。为了演示方便，这里选择用快捷键「F2」进行触发。

![](https://cdn.jsdelivr.net/gh/wuzimuws/imgbed@main/img/202403171732789.png)

➂ 设置动作

假如，目标文本文档储存在桌面上，名称为 `Saved.txt`，那么动作就可以拆解为：

* 拷贝文本
* 打开桌面的 `Saved.txt`文本文档
* 找到最后一行（通过模拟「⌘↓」按键来实现）
* 粘贴
* 换行（通过模拟「Return」按键来实现）
* 保存（通过模拟「⌘S」按键来实现）
* 退出（通过模拟「⌘W」按键来实现）
* 激活上一个应用程序

![](https://cdn.jsdelivr.net/gh/wuzimuws/imgbed@main/img/202403171758345.png)

<figure><img src="https://cdn.jsdelivr.net/gh/wuzimuws/imgbed@main/img/202403171756947.gif" alt=""><figcaption></figcaption></figure>

在上述示例的基础上，为了区分保存时间，还可以插入时间戳，由于时间戳是变量，因此，上述任务就变成了「变动无交互式任务」，具体区别见下图。

![](https://cdn.jsdelivr.net/gh/wuzimuws/imgbed@main/img/202403171815774.png)

这个宏中不仅引入了[变量](/bian-liang.md)`%LongDate% %ShortTime%`，还使用了[命名剪贴板](/jian-tie-ban.md)`Named Clipboard`。具体使用方法，请参见链接。


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://km.qxpai.cn/keyboard-maestro-jian-jie.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
