Window & Search Bar

API Reference

clearSearchBar

Clear the text in the search bar.

Signature

1
async function clearSearchBar(options: {
2
forceScrollToTop: boolean;
3
}): Promise<void>;
Copied!

Parameters

Name
Type
Required
Description
options
{ forceScrollToTop: boolean }
No
Can be used to force scrolling to the top. Defaults to scrolling to the top after the search bar was cleared.

Return

A Promise that resolves when the search bar is cleared.

closeMainWindow

Closes the main Raycast window.

Signature

1
async function closeMainWindow(options: {
2
clearRootSearch: boolean;
3
}): Promise<void>;
Copied!

Example

1
import { closeMainWindow } from "@raycast/api";
2
import { setTimeout } from "timers/promises";
3
4
export default async () => {
5
await setTimeout(1000);
6
await closeMainWindow({ clearRootSearch: true });
7
};
Copied!

Parameters

Name
Type
Required
Description
options
{ clearRootSearch: boolean }
No
Can be used to clear the root search. Defaults to not clearing the root search after the window was closed.

Return

A Promise that resolves when the main window is closed.

openExtensionPreferences

Opens the extension's preferences screen.

Signature

1
export declare function openExtensionPreferences(): Promise<void>;
Copied!

Example

1
import { ActionPanel, Action, Detail, openExtensionPreferences } from "@raycast/api";
2
3
export default function Command() {
4
const markdown = `
5
API key incorrect. Please update it in extension preferences and try again.
6
`;
7
return (
8
<Detail
9
markdown={markdown}
10
actions={
11
<ActionPanel>
12
<Action title="Open Extension Preferences" onAction={openExtensionPreferences} />
13
</ActionPanel>
14
}
15
/>
16
);
17
}
Copied!

Return

A Promise that resolves when the extensions preferences screen is opened.

openCommandPreferences

Opens the command's preferences screen.

Signature

1
export declare function openCommandPreferences(): Promise<void>;
Copied!

Example

1
import { ActionPanel, Action, Detail, openCommandPreferences } from "@raycast/api";
2
3
export default function Command() {
4
const markdown = `
5
API key incorrect. Please update it in command preferences and try again.
6
`;
7
return (
8
<Detail
9
markdown={markdown}
10
actions={
11
<ActionPanel>
12
<Action title="Open Extension Preferences" onAction={openCommandPreferences} />
13
</ActionPanel>
14
}
15
/>
16
);
17
}
Copied!

Return

A Promise that resolves when the command's preferences screen is opened.

popToRoot

Pops the navigation stack back to root search.

Signature

1
async function popToRoot(options: { clearSearchBar: boolean }): Promise<void>;
Copied!

Example

1
import { Detail, popToRoot } from "@raycast/api";
2
import { useEffect } from "react";
3
import { setTimeout } from "timers";
4
5
export default function Command() {
6
useEffect(() => {
7
setTimeout(() => {
8
popToRoot({ clearSearchBar: true });
9
}, 3000);
10
}, []);
11
12
return <Detail markdown="See you soon 👋" />;
13
}
Copied!

Parameters

Name
Type
Required
Description
options
{ clearSearchBar: boolean }
No
Can be used to clear the search bar. Defaults to clearing the search bar after popped to root.

Return

A Promise that resolves when Raycast popped to root.