Raycast 中文文档
  • 介绍
  • 链接
    • 官网
    • 官网 API 文档
    • 社区
    • GitHub
    • Store
    • Icon 生成器
    • 扩展图标模板
  • 基础
    • 起步
    • 创建您的第一个扩展
    • 贡献一个扩展
    • 过审一个扩展
    • 发布一个扩展
    • 调试一个扩展
    • 安装一个扩展
  • 团队
    • 开始
    • 发布私人扩展
    • 协作开发私有扩展
  • 例子
    • Doppler 共享 Secrets
    • Hacker News
    • Todo 列表
    • Spotify Controls
  • 资料
    • 最佳实践
    • 工具
      • CLI
      • ESLint
      • VS Code(社区工具)
    • 文件结构
    • 生命周期
      • 参数
      • 后台刷新
      • Deeplinks
    • Manifest
    • 安全性
    • 术语
    • 版本控制
  • API 参考
    • AI
    • Cache
    • Command
    • Clipboard
    • Environment
    • Feedback
      • Alert
      • HUD
      • Toast
    • Keyboard
    • Menu Bar Commands
    • OAuth
    • Preferences
    • Storage
    • System Utilities
    • 用户界面
      • Action Panel
      • Actions
      • Detail
      • Form
      • List
      • Grid
      • Colors
      • Icons & Images
      • Navigation
    • 窗口 & 搜索栏
  • 公共包
    • 起步
    • 功能
      • 执行 AppleScript
    • 图标
      • getAvatarIcon
      • getFavicon
      • getProgressIcon
    • React hooks
      • useCachedState
      • usePromise
      • useCachedPromise
      • useFetch
      • useForm
      • useExec
      • useSQL
      • useAI
  • 迁移
  • FAQ
由 GitBook 提供支持
在本页
  • API 参考
  • Action
  • Action.CopyToClipboard
  • Action.Open
  • Action.OpenInBrowser
  • Action.OpenWith
  • Action.Paste
  • Action.Push
  • Action.ShowInFinder
  • Action.SubmitForm
  • Action.Trash
  • Action.CreateSnippet
  • Action.CreateQuicklink
  • Action.ToggleQuickLook
  • Action.PickDate
  • 类型
  • Snippet
  • Quicklink
  • Action.Style
  • Action.PickDate.Type
  1. API 参考
  2. 用户界面

Actions

上一页Action Panel下一页Detail

最后更新于1年前

我们的 API 包括一些可用于常见交互的内置操作,例如打开链接或将某些内容复制到剪贴板。通过使用它们,您确保遵循我们的人机界面指南。如果您需要自定义内容,请使用 组件。所有内置操作都只是其之上的抽象。

API 参考

Action

用户可以执行的特定于上下文的操作。

为项目分配键盘快捷键,以便用户更轻松地执行常用操作。

例子

import { ActionPanel, Action, List } from "@raycast/api";

export default function Command() {
  return (
    <List navigationTitle="Open Pull Requests">
      <List.Item
        title="Docs: Update API Reference"
        subtitle="#1"
        actions={
          <ActionPanel title="#1 in raycast/extensions">
            <Action.OpenInBrowser url="https://github.com/raycast/extensions/pull/1" />
            <Action.CopyToClipboard title="Copy Pull Request Number" content="#1" />
            <Action title="Close Pull Request" onAction={() => console.log("Close PR #1")} />
          </ActionPanel>
        }
      />
    </List>
  );
}

参数

名称
描述
类型
默认

title*

Action 显示的标题。

string

-

autoFocus

当父 ActionPanel(或 Actionpanel.Submenu)打开时,Action 是否自动获得焦点。

boolean

-

icon

Action 显示的图标。

-

shortcut

Action 的键盘快捷键。

-

style

Action 的样式。

onAction

Action 触发的回调。

() => void

-

Action.CopyToClipboard

将内容复制到剪贴板的操作。

主窗口关闭,内容复制到剪贴板后会显示 HUD。

例子

import { ActionPanel, Action, Detail } from "@raycast/api";

export default function Command() {
  return (
    <Detail
      markdown="Press `⌘ + .` and share some love."
      actions={
        <ActionPanel>
          <Action.CopyToClipboard content="I ❤️ Raycast" shortcut={{ modifiers: ["cmd"], key: "." }} />
        </ActionPanel>
      }
    />
  );
}

参数

名称
描述
类型
默认

content*

将复制到剪贴板的内容。

-

icon

Action 显示的可选图标。

shortcut

Aciton 的键盘快捷键。

-

title

Action 的可选标题。

string

"Copy to Clipboard"

transient

是否应将内容暂时复制到剪贴板。

boolean

false

onCopy

内容复制到剪贴板时的回调。

-

Action.Open

使用特定应用程序打开文件或文件夹的操作,就像双击文件的图标一样。

文件打开后主窗口关闭。

例子

import { ActionPanel, Detail, Action } from "@raycast/api";

export default function Command() {
  return (
    <Detail
      markdown="Check out your extension code."
      actions={
        <ActionPanel>
          <Action.Open title="Open Folder" target={__dirname} />
        </ActionPanel>
      }
    />
  );
}

参数

名称
描述
类型
默认

target*

要打开的文件、文件夹或 URL。

string

-

title*

Action 的标题。

string

-

application

用于打开文件的应用程序名称。

-

icon

Action 显示的图标。

shortcut

Action 的键盘快捷键。

-

onOpen

文件或文件夹打开时的回调。

(target: string) => void

-

Action.OpenInBrowser

在默认浏览器中打开 URL 的操作。

在浏览器中打开 URL 后,主窗口将关闭。

例子

import { ActionPanel, Detail, Action } from "@raycast/api";

export default function Command() {
  return (
    <Detail
      markdown="Join the gang!"
      actions={
        <ActionPanel>
          <Action.OpenInBrowser url="https://raycast.com/jobs" />
        </ActionPanel>
      }
    />
  );
}

参数

名称
描述
类型
默认

url*

要打开的网址。

string

-

icon

Action 显示的图标。

shortcut

Action 的可选键盘快捷键。

-

title

Action

的可选标题。

string

"Open in Browser"

onOpen

在浏览器中打开 URL 时的回调。

(url: string) => void

-

Action.OpenWith

使用特定应用程序打开文件或文件夹的操作。

该操作将打开一个子菜单,其中包含可以打开该文件或文件夹的所有应用程序。在指定应用程序中打开文件后,主窗口将关闭。

例子

import { ActionPanel, Detail, Action } from "@raycast/api";
import { homedir } from "os";

const DESKTOP_DIR = `${homedir()}/Desktop`;

export default function Command() {
  return (
    <Detail
      markdown="What do you want to use to open your desktop with?"
      actions={
        <ActionPanel>
          <Action.OpenWith path={DESKTOP_DIR} />
        </ActionPanel>
      }
    />
  );
}

参数

Prop
Description
Type
Default

path*

要打开的路径。

string

-

icon

Action 显示的图标。

shortcut

Action 的键盘快捷键。

-

title

Action 的标题。

string

"Open With"

onOpen

文件或文件夹打开时的回调。

(path: string) => void

-

Action.Paste

将内容粘贴到最前置的应用程序的操作。

将内容粘贴到最前置的应用程序后,主窗口将关闭。

例子

import { ActionPanel, Detail, Action } from "@raycast/api";

export default function Command() {
  return (
    <Detail
      markdown="Let us know what you think about the Raycast API?"
      actions={
        <ActionPanel>
          <Action.Paste content="api@raycast.com" />
        </ActionPanel>
      }
    />
  );
}

参数

名称
描述
类型
默认

content*

将粘贴到最前置的应用程序的内容。

-

icon

Action 显示的图标。

shortcut

Action 的键盘快捷键。

-

title

Action 的可选标题。

string

"Paste in Active App"

onPaste

将内容粘贴到最前置的应用程序时的回调。

-

Action.Push

将新 view 推送到导航堆栈的操作。

例子

import { ActionPanel, Detail, Action } from "@raycast/api";

function Ping() {
  return (
    <Detail
      markdown="Ping"
      actions={
        <ActionPanel>
          <Action.Push title="Push Pong" target={<Pong />} />
        </ActionPanel>
      }
    />
  );
}

function Pong() {
  return <Detail markdown="Pong" />;
}

export default function Command() {
  return <Ping />;
}

参数

名称
描述
类型
默认

target*

将推送到导航堆栈的目标 view。

React.ReactNode

-

title*

Action 显示的标题。

string

-

icon

Action 显示的图标。

-

shortcut

Action 显示的快捷键

-

onPush

推送目标 view 时的回调。

() => void

-

Action.ShowInFinder

在 Finder 中显示文件或文件夹的操作。

文件或文件夹在 Finder 中显示后,主窗口将关闭。

例子

import { ActionPanel, Detail, Action } from "@raycast/api";
import { homedir } from "os";

const DOWNLOADS_DIR = `${homedir()}/Downloads`;

export default function Command() {
  return (
    <Detail
      markdown="Are your downloads pilling up again?"
      actions={
        <ActionPanel>
          <Action.ShowInFinder path={DOWNLOADS_DIR} />
        </ActionPanel>
      }
    />
  );
}

参数

名称
描述
类型
默认

path*

要打开的路径。

-

icon

Action 显示的可选图标。

shortcut

Action 显示的快捷键

-

title

Action 的可选标题。

string

"Show in Finder"

onShow

文件或文件夹显示在 Finder 中时的回调。

-

Action.SubmitForm

添加用于捕获表单值的提交处理程序的操作。

例子

import { ActionPanel, Form, Action } from "@raycast/api";

export default function Command() {
  return (
    <Form
      actions={
        <ActionPanel>
          <Action.SubmitForm title="Submit Answer" onSubmit={(values) => console.log(values)} />
        </ActionPanel>
      }
    >
      <Form.Checkbox id="answer" label="Are you happy?" defaultValue={true} />
    </Form>
  );
}

参数

名称
描述
类型
默认

icon

Action 显示的图标。

-

shortcut

Action 显示的快捷键

-

title

Action 显示的标题

string

"Submit Form"

onSubmit

表单提交时的回调。该处理程序接收包含用户输入的值对象。

-

Action.Trash

将文件或文件夹移至废纸篓的操作。

例子

import { ActionPanel, Detail, Action } from "@raycast/api";
import { homedir } from "os";

const FILE = `${homedir()}/Downloads/get-rid-of-me.txt`;

export default function Command() {
  return (
    <Detail
      markdown="Some spring cleaning?"
      actions={
        <ActionPanel>
          <Action.Trash paths={FILE} />
        </ActionPanel>
      }
    />
  );
}

参数

名称
描述
类型
默认

paths*

要移至垃圾箱的一个或多个项。

-

icon

Action 显示的可选图标。

shortcut

Action 的可选键盘快捷键。

-

title

Action 的可选标题。

string

"Move to Trash"

onTrash

当所有项目都移至垃圾箱时回调。

-

Action.CreateSnippet

导航到 “Create Snippet” 命令并预填充字段的操作

例子

import { ActionPanel, Detail, Action } from "@raycast/api";

export default function Command() {
  return (
    <Detail
      markdown="Test out snippet creation"
      actions={
        <ActionPanel>
          <Action.CreateSnippet snippet={{ text: "DE75512108001245126199" }} />
        </ActionPanel>
      }
    />
  );
}

参数

名称
描述
类型
默认

snippet*

-

icon

-

shortcut

Action 的快捷键

-

title

Action 的标题

string

-

Action.CreateQuicklink

导航到 “Create Quicklink” 命令并预填充字段的操作。

例子

import { ActionPanel, Detail, Action } from "@raycast/api";

export default function Command() {
  return (
    <Detail
      markdown="Test out quicklink creation"
      actions={
        <ActionPanel>
          <Action.CreateQuicklink quicklink={{ link: "https://duckduckgo.com/?q={Query}" }} />
        </ActionPanel>
      }
    />
  );
}

参数

名称
描述
类型
默认

quicklink*

-

icon

-

shortcut

Action 的快捷键

-

title

Action 的可选标题。

string

-

Action.ToggleQuickLook

切换 “Quick Look” 以预览文件的操作。

例子

import { ActionPanel, List, Action } from "@raycast/api";

export default function Command() {
  return (
    <List>
      <List.Item
        title="Preview me"
        quickLook={{ path: "~/Downloads/Raycast.dmg", name: "Some file" }}
        actions={
          <ActionPanel>
            <Action.ToggleQuickLook shortcut={{ modifiers: ["cmd"], key: "y" }} />
          </ActionPanel>
        }
      />
    </List>
  );
}

参数

名称
描述
类型
默认

icon

Action 显示的图标.

shortcut

Action 的键盘快捷键。

-

title

Action 的标题。

string

"Quick Look"

Action.PickDate

选择日期的 Action。

例子

import { ActionPanel, List, Action } from "@raycast/api";

export default function Command() {
  return (
    <List>
      <List.Item
        title="Todo"
        actions={
          <ActionPanel>
            <Action.PickDate title="Set Due Date…" />
          </ActionPanel>
        }
      />
    </List>
  );
}

参数

名称
描述
类型
默认

title*

Action 的标题.

string

-

onChange*

选择日期时的回调

(date: Date) => void

-

icon

Action 显示的可选图标。

max

允许选择的最长日期(含)。

Date

-

min

允许选择的最短日期(含)。

Date

-

shortcut

Action 的键盘快捷键。

-

type

可以选择哪些类型的日期组件

-

类型

Snippet

属性

名称
描述
Type

text*

代码片段内容。

string

keyword

触发代码片段的关键字。

string

name

代码片段名称。

string

Quicklink

属性

名称
描述
类型

link*

URL 或文件路径,可以选择包含占位符,例如“https://google.com/search?q={Query}”

string

application

在其中打开快速链接的应用程序。

name

快链名称

string

Action.Style

定义操作的样式。

Action.PickDate.Type

用户可以使用 Action.PickDate 选择日期组件的类型。

枚举成员

名称
描述

DateTime

除了年、月、日之外,还可以选择时、秒

Date

只能选择年、月、日

string 或 number 或

(content: string | number | ) => void

string 或

string 或 number 或

(content: string | number | ) => void

(path: ) => void

(input: ) => boolean | void | Promise<boolean | void>

or []

(paths: | []) => void

Action 显示的可选图标。有关支持的格式和类型,请参阅 。

要创建的 。

Action 显示的可选图标。有关支持的格式和类型,请参阅 。

string 或

使用 显示常规操作。当您的操作包含用户应该注意的内容时,请使用 。如果操作正在执行用户无法恢复的操作,请使用 。

Action
Alert
Action.Style.Regular
Action.Style.Destructive
Action.Style.Regular
Snippet
Quicklink
Quicklink
Action.PickDate.Type
Clipboard.Content
Clipboard.Content
Clipboard.Content
Clipboard.Content
Application
PathLike
PathLike
PathLike
PathLike
PathLike
PathLike
Application
Image.ImageLike
Image.ImageLike
Icon.Clipboard
Image.ImageLike
Icon.Finder
Image.ImageLike
Icon.Globe
Image.ImageLike
Icon.Upload
Image.ImageLike
Icon.Clipboard
Image.ImageLike
Image.ImageLike
Icon.Finder
Image.ImageLike
Image.ImageLike
Icon.Trash
Image.ImageLike
Image.ImageLike
Image.ImageLike
Image.ImageLike
Image.ImageLike
Icon.Eye
Image.ImageLike
Icon.Calendar
Keyboard.Shortcut
Keyboard.Shortcut
Keyboard.Shortcut
Keyboard.Shortcut
Keyboard.Shortcut
Keyboard.Shortcut
Keyboard.Shortcut
Keyboard.Shortcut
Keyboard.Shortcut
Keyboard.Shortcut
Keyboard.Shortcut
Keyboard.Shortcut
Keyboard.Shortcut
Keyboard.Shortcut
Alert.ActionStyle
Form.Values