# Smart rules and script plugins

> Process clipboard items automatically with smart rules, built-in text transforms and JavaScript script plugins.

A smart rule has conditions and actions. When something new reaches your clipboard, Deck checks the rules from top to bottom. For each rule whose conditions match, Deck runs its actions.

## Create a rule

1. Open **Settings › Smart Rules**.
2. Select **Add Rule** (the plus button), or **Add First Rule** if the list is empty.
3. Enter a **Rule Name**.
4. Choose how conditions combine: **Match All** (every condition must match) or **Match Any** (one is enough).
5. Select **Add condition** and **Add action** until the rule does what you want, then select **Save**.

Rules run in list order. Drag a rule to change its priority. Two preset rules, **Detect API Key** and **Detect Password**, are created the first time you use the feature. They are off until you turn them on.

> [!TIP]
> Keep conditions narrow. A rule with only **Content Type** set to text matches almost everything you copy.

## Conditions

| Condition | What it checks |
|---|---|
| **Content contains** | The item's text contains the value you enter. |
| **Content matches regex** | The item's text matches a regular expression. |
| **Content Type** | The item is **Text**, **Images**, **File**, **Links**, **Code** or **Colors**. |
| **Source App** | The name of the app the item was copied from. |
| **Has Custom Title** | The item has a title you gave it. This condition has no value. |
| **Content Length** | The number of characters is **Greater than**, **Less than** or **Equals** the number you enter. |

## Actions

| Action | What it does |
|---|---|
| **Add Tag** | Adds a tag with the name you enter. Deck creates the tag if it does not exist. |
| **Mark as Sensitive** | Marks the item as sensitive. |
| **Auto Delete** | Deletes the item after the number of minutes you choose. Items that already have a tag are skipped. |
| **Transform** | Rewrites the text with one of the built-in transforms below, before the item is saved. |
| **Script Plugins** | Rewrites the text with an installed script plugin. |
| **AI Automation** | Runs an AI prompt on the item. See below. |
| **Don't Save** | Keeps the item out of your history. |

### AI automation

An **AI Automation** action needs a prompt. It runs on its own each time the rule matches, and Deck does not ask for confirmation. When you add the action, the app warns you about this high-permission mode.

- The AI can work only on the item that triggered the rule, not on other items.
- It can search the web and read web pages.
- It cannot create, change or delete script plugins or smart rules.

Write the prompt narrowly, and treat text fetched from the web as data, not as instructions.

## Share rules

- To export rules, use the export option on a rule. Deck saves a `.deckrule` file.
- To import rules, select **Import Rules** and choose a `.deckrule` file. Deck shows how many rules the file holds and asks you to confirm.
- A rule can also be shared as a `deck://install-rule?payload=…` link. Opening the link in Deck offers to install the rule.

## Built-in text transforms

These 18 transforms are available as a rule action and in the item menu. To use one by hand, right-click a text item and choose **Convert and Paste**. Deck pastes the transformed text.

| Transform | What it does |
|---|---|
| **JSON Format** | Pretty-prints JSON with sorted keys. |
| **JSON Minify** | Removes whitespace from JSON. |
| **URL Encode** | Percent-encodes text. |
| **URL Decode** | Decodes percent-encoded text. |
| **Base64 Encode** | Encodes UTF-8 text as Base64. |
| **Base64 Decode** | Decodes Base64 into text. |
| **Camel to Snake Case** | `userName` becomes `user_name`. |
| **Snake to Camel Case** | `user_name` becomes `userName`. |
| **Timestamp to Date** | Turns a Unix timestamp in seconds or milliseconds into `yyyy-MM-dd HH:mm:ss` in your time zone. |
| **Uppercase** | Converts to uppercase. |
| **Lowercase** | Converts to lowercase. |
| **Trim Whitespace** | Removes whitespace at both ends. |
| **Escape HTML** | Replaces HTML special characters with entities. |
| **Unescape HTML** | Turns HTML entities back into characters. |
| **MD5 Hash** | Returns the MD5 hash in lowercase hexadecimal. |
| **Sort Lines** | Sorts the lines. |
| **Remove Duplicate Lines** | Removes repeated lines. |
| **Reverse Text** | Reverses the text. |

If a transform cannot apply, for example **JSON Format** on text that is not JSON, the item is left unchanged.

## Script plugins

A script plugin is a small JavaScript program that turns the text of an item into new text. Deck installs a few examples the first time it runs, such as word count and remove empty lines.

### Plugin folder

Each plugin is a folder in `~/.deck/scripts/`. The folder name is the plugin ID.

```text
~/.deck/scripts/my-plugin/
  manifest.json
  index.js
```

Deck watches the folder, so new and edited plugins load without a restart.

### manifest.json

```json
{
  "name": "Sample Plugin",
  "description": "Processes input text",
  "author": "Your Name",
  "version": "1.0.0",
  "main": "index.js",
  "icon": "wand.and.stars",
  "permissions": {
    "network": false
  }
}
```

| Field | Meaning |
|---|---|
| `name`, `description`, `author`, `version` | Shown in the plugin list. |
| `main` | The script file, inside the plugin folder. |
| `icon` | The name of an SF Symbol. |
| `permissions.network` | `true` if the plugin needs to make web requests. The default is `false`. |

### index.js

The script defines `transform(input)`. It receives the item's text and returns the new text as a string.

```js
function transform(input) {
  var text = String(input || "");
  var lines = text.split("\n")
    .map(function (line) { return line.trim(); })
    .filter(function (line) { return line.length > 0; });
  return lines.join("\n");
}
```

Available inside a plugin:

| API | What it does |
|---|---|
| `Deck.detectURLs(text)` | Returns the URLs found in the text, one per line. |
| `Deck.detectEmails(text)` | Returns the email addresses found in the text, one per line. |
| `Deck.shouldStop()` and `Deck.checkInterrupt()` | Return whether Deck wants the script to stop. Check them in long loops. |
| `btoa(text)` and `atob(text)` | Base64 encode and decode. |
| `console.log`, `console.warn`, `console.error` | Write log messages. |
| `fetch(url, options)` | Makes a web request. Needs network permission. |

`fetch` is synchronous. It returns an object with `status`, `text()` and, on failure, `error`.

```js
function transform(input) {
  var response = fetch(String(input || "").trim(), {
    method: "GET",
    headers: { "accept": "application/json" }
  });
  if (!response || response.error) {
    return "Request failed: " + ((response && response.error) || "Unknown error");
  }
  return "status: " + response.status + "\n" + response.text();
}
```

### Network permission

A plugin can use `fetch` only when both of these are true:

1. Its `manifest.json` sets `"network": true`.
2. You authorized network access for that plugin in Deck's script plugin settings.

Authorization applies to the script you reviewed. If the script changes, authorize it again. Only `http` and `https` addresses work, a response can be about 2 MB at most, and requests do not share cookies with any app.

A rule cannot run a network plugin you have not authorized.

### Limits

- Each run starts in a clean environment. Nothing is kept between runs.
- A run is stopped after 5 seconds by default.
- Input and output are limited to 100,000 characters each.
- `manifest.json` can be about 64 KB and the script about 1 MB.
- Plugins cannot read or write files or run system commands.

### Use a plugin

- Right-click a text item, choose **Convert and Paste**, and pick the plugin from the list under the built-in transforms.
- Add a **Script Plugins** action to a smart rule.
- Run it from the command line: `deckclip ai transform "prompt" --plugin my-plugin`. See [The deckclip command line](https://deckclip.app/docs/automation/cli).
- Let an AI tool use it. See [AI assistant](https://deckclip.app/docs/automation/ai-assistant) and [MCP](https://deckclip.app/docs/automation/mcp).

To install a plugin someone shared as a `deck://install-plugin?…` link, open the link in Deck.

- Previous: [Share between Macs](https://deckclip.app/docs/guides/lan-sharing.md)
- Next: [Siri and Shortcuts](https://deckclip.app/docs/automation/shortcuts.md)

---

- HTML: https://deckclip.app/docs/automation/smart-rules
- 中文: https://deckclip.app/zh-cn/docs/automation/smart-rules.md

© 2026 Yuze Pan
