Utilities
This list of Utility APIs make 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 deeplink 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(`Default application for JavaScript is: ${defaultApplication.name}`);
6
};
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.

randomId

Generate secure URL-friendly unique ID.

Signature

1
function randomId(size: number): string
Copied!

Example

1
import { pasteText, randomId } from "@raycast/api";
2
3
export default async () => {
4
const id = randomId();
5
await pasteText(id);
6
};
Copied!

Parameters

Name
Type
Required
Description
size
number
No
Size of the ID. The default size is 21.

Return

A random string.

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
showInFinder(homedir(), "Downloads")
Copied!

Parameters

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

Return

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

trash

Moves a file or director 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
5
export default async () => {
6
const file = `${homedir()}/Desktop/yolo.txt`;
7
await writeFile(file, "I will be deleted soon!");
8
await trash(file);
9
};
Copied!

Parameters

Name
Type
Required
Description
path
PathLike or PathLike[]
Yes

Return

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

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

Name
Type
Required
Description
bundleId
string
No
The bundle identifier of the application, e.g. com.raycast.macos.
name
string
Yes
The display name of the application.
path
string
Yes
The absolute path to the application bundle, e.g. /Applications/Raycast.app,
Last modified 1d ago