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

1
import { environment } from "@raycast/api";
2
3
console.log(`Raycast version: ${environment.raycastVersion}`);
4
console.log(`Extension name: ${environment.extensionName}`);
5
console.log(`Command name: ${environment.commandName}`);
6
console.log(`Assets path: ${environment.assetsPath}`);
7
console.log(`Support path: ${environment.supportPath}`);
8
console.log(`Is development mode: ${environment.isDevelopment}`);
9
console.log(`Theme: ${environment.theme}`);
Copied!

Properties

Property
Description
Type
assetsPath*
The absolute path to the assets directory of the extension.
string
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
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
theme*
The theme used by the Raycast application.
"light" or "dark"

getSelectedFinderItems

Gets the selected items from Finder.

Signature

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

Example

1
import { getSelectedFinderItems, Clipboard, showToast, Toast } from "@raycast/api";
2
3
export default async () => {
4
try {
5
const selectedItems = await getSelectedFinderItems();
6
if (selectedItems.length) {
7
await Clipboard.paste(selectedItems[0].path);
8
}
9
} catch (error) {
10
await showToast({
11
style: Toast.Style.Failure,
12
title: "Cannot copy file path",
13
message: String(error),
14
});
15
}
16
};
Copied!

Return

A Promise that resolves with the selected file system items.

getSelectedText

Gets the selected text of the frontmost application.

Signature

1
async function getSelectedText(): Promise<string>;
Copied!

Example

1
import { getSelectedText, Clipboard, showToast, Toast } from "@raycast/api";
2
3
export default async () => {
4
try {
5
const selectedText = await getSelectedText();
6
const transformedText = selectedText.toUpperCase();
7
await Clipboard.paste(transformedText);
8
} catch (error) {
9
await showToast({
10
style: Toast.Style.Failure,
11
title: "Cannot transform text",
12
message: String(error),
13
});
14
}
15
};
Copied!

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