Links

Environment

The Environment APIs are useful to get context about the setup in which your command runs. You can get information about the extension and command itself as well as Raycast. Furthermore, a few paths are injected and are helpful to construct file paths that are related to the command's assets.

API Reference

environment

Contains environment values such as the Raycast version, extension info, and paths.

Example

import { environment } from "@raycast/api";
export default async function Command() {
console.log(`Raycast version: ${environment.raycastVersion}`);
console.log(`Extension name: ${environment.extensionName}`);
console.log(`Command name: ${environment.commandName}`);
console.log(`Command mode: ${environment.commandMode}`);
console.log(`Assets path: ${environment.assetsPath}`);
console.log(`Support path: ${environment.supportPath}`);
console.log(`Is development mode: ${environment.isDevelopment}`);
console.log(`Theme: ${environment.theme}`);
console.log(`Text size: ${environment.textSize}`);
console.log(`LaunchType: ${environment.launchType}`);
}

Properties

Property
Description
Type
assetsPath*
The absolute path to the assets directory of the extension.
string
commandMode*
The mode of the launched command, as specified in package.json
"no-view" or "view" or "menu-bar"
commandName*
The name of the launched command, as specified in package.json
string
extensionName*
The name of the extension, as specified in package.json
string
isDevelopment*
Indicates whether the command is a development command (vs. an installed command from the Store).
boolean
launchType*
The type of launch for the command (user initiated or background).
raycastVersion*
The version of the main Raycast app
string
supportPath*
The absolute path for the support directory of an extension. Use it to read and write files related to your extension or command.
string
textSize*
The text size used by the Raycast application.
"medium" or "large"
theme*
The theme used by the Raycast application.
"light" or "dark"
launchContext
Any custom context values passed from a programmatic command launch via launchCommand.

getSelectedFinderItems

Gets the selected items from Finder.

Signature

async function getSelectedFinderItems(): Promise<FileSystemItem[]>;

Example

import { getSelectedFinderItems, showToast, Toast } from "@raycast/api";
export default async function Command() {
try {
const selectedItems = await getSelectedFinderItems();
console.log(selectedItems);
} catch (error) {
await showToast({
style: Toast.Style.Failure,
title: "Cannot copy file path",
message: String(error),
});
}
}

Return

A Promise that resolves with the selected file system items.

getSelectedText

Gets the selected text of the frontmost application.

Signature

async function getSelectedText(): Promise<string>;

Example

import { getSelectedText, Clipboard, showToast, Toast } from "@raycast/api";
export default async function Command() {
try {
const selectedText = await getSelectedText();
const transformedText = selectedText.toUpperCase();
await Clipboard.paste(transformedText);
} catch (error) {
await showToast({
style: Toast.Style.Failure,
title: "Cannot transform text",
message: String(error),
});
}
}

Return

A Promise that resolves with the selected text.

Types

FileSystemItem

Holds data about a File System item. Use the getSelectedFinderItems method to retrieve values.

Properties

Property
Description
Type
path*
The path to the item
string

LaunchType

Indicates the type of command launch. Use this to detect whether the command has been launched from the background.

Enumeration members

Name
Description
UserInitiated
A regular launch through user interaction
Background
Scheduled through an interval and launched from background

LaunchContext

Represents the passed context object of programmatic command launches.