Utilities
This list of Utility APIs makes your life easier as a developer. They also expose some of Raycast's native functionality to allow deep integration into the user's setup. For example, you can use the Application APIs to check if a desktop application is installed and then provide an action to deep-link into it.

API Reference

getApplications

Returns all applications that can open the file.

Signature

1
async function getApplications(path?: PathLike): Promise<Application[]>;
Copied!

Example

1
import { getApplications } from "@raycast/api";
2
3
export default async () => {
4
const installedApplications = await getApplications();
5
console.log("The following applications are installed on your Mac:");
6
console.log(installedApplications.map((a) => a.name).join(", "));
7
};
Copied!

Parameters

Name
Type
Required
Description
path
PathLike
No
The path of the file or folder to get the applications for. If no path is specified, all installed applications are returned.

Return

An array of Application.

getDefaultApplication

Returns the default application that the file would be opened with.

Signature

1
async function getDefaultApplication(path: PathLike): Promise<Application>;
Copied!

Example

1
import { getDefaultApplication } from "@raycast/api";
2
3
export default async () => {
4
const defaultApplication = await getDefaultApplication(__filename);
5
console.log(
6
`Default application for JavaScript is: ${defaultApplication.name}`
7
);
8
};
Copied!

Parameters

Name
Type
Required
Description
path
PathLike
Yes
The path of the file or folder to get the default application for.

Return

The default Application that would open the file. Throws an error if no application was found.

showInFinder

Shows a file or directory in the Finder.

Signature

1
async function showInFinder(path: PathLike): Promise<void>;
Copied!

Example

1
import { showInFinder } from "@raycast/api";
2
import { homedir } from "os";
3
import { join } from "path";
4
5
showInFinder(join(homedir(), "Downloads"));
Copied!

Parameters

Name
Type
Required
Description
path
PathLike
Yes
The path to show in the Finder.

Return

A Promise that resolves when the item is revealed in the Finder.

trash

Moves a file or directory to the Trash.

Signature

1
async function trash(path: PathLike | PathLike[]): Promise<void>;
Copied!

Example

1
import { trash } from "@raycast/api";
2
import { writeFile } from "fs/promises";
3
import { homedir } from "os";
4
import { join } from "path";
5
6
export default async () => {
7
const file = join(homedir(), "Desktop", "yolo.txt");
8
await writeFile(file, "I will be deleted soon!");
9
await trash(file);
10
};
Copied!

Parameters

Name
Type
Required
Description
path
Yes

Return

A Promise that resolves when all files are moved to the trash.

open

Opens a target with the default application or specified application.

Signature

1
async function open(
2
target: string,
3
application?: Application | string
4
): Promise<void>;
Copied!

Example

1
import { open } from "@raycast/api";
2
3
export default async () => {
4
await open("https://www.raycast.com", "com.google.Chrome");
5
};
Copied!

Parameters

Name
Type
Required
Description
target
string
Yes
The file, folder or URL to open
application
Application or string
No
The application name to use for opening the file. If no application is specified, the default application as determined by the system is used to open the specified file. Note that you can use the application name, app identifier, or absolute path to the app.

Return

A Promise that resolves when the target has been opened.

Types

Application

An object that represents a locally installed application on the system.
It can be used to open files or folders in a specific application. Use getApplications or getDefaultApplication to get applications that can open a specific file or folder.

Properties

Property
Description
Type
name*
The display name of the application.
string
path*
The absolute path to the application bundle, e.g. /Applications/Raycast.app,
string
bundleId
The bundle identifier of the application, e.g. com.raycast.macos.
string

PathLike

1
PathLike: string | Buffer | URL;
Copied!
Supported path types.