Preferences
Use the Preferences API to make your extension configurable. Preferences can be configured per command or shared in the context of an extension. Required preferences need to be set by the user before a command opens. They are great a way to make sure that the user of your extension has everything set up properly.

API Reference

getPreferenceValues

A convenience function for type-safe access to the values of the preferences object.
Each preference name is mapped to its value and the defined default values are used as fallback values.

Signature

1
function getPreferenceValues(): Values
Copied!

Example

1
import { getPreferenceValues } from "@raycast/api";
2
3
interface Preferences {
4
name: string;
5
bodyWeight?: string;
6
bodyHeight?: string;
7
}
8
9
export default async () => {
10
const preferences: Preferences = getPreferenceValues();
11
console.log(preferences);
12
};
Copied!

Return

An object with the preference names as property key and the typed value as property value.

preferences

1
preferences: Preferences = workerData.preferences
Copied!
Contains the preference values that have been passed to the command.

Preference

Holds data about a single preference item (entered in Raycast Preferences). Use the getPreferenceValues function or the global preferences object to retrieve values.
The object maps to a defined preference in the package.json manifest file.

Properties

Name
Type
Required
Description
data
unknown[]
No
The data that is used for dropdowns. For the dropdown items, add an array of objects with title and value properties, such as: {"title": "Foo", "value": "bar"}
default
unknown
No
The default value of the preference if there is no value specified. For dropdowns, this references the value property of an object in the data array.
description
string
Yes
The description of the preference.
label
string
No
A label that is used for checkboxes. You can create checkbox groups by setting this property and leaving the title property empty for all checkboxes except the first.
name
string
Yes
The name of the preference.
placeholder
string
No
A placeholder that is used for text fields and passwords.
required
boolean
Yes
Specifies if the preference is required.
title
string
Yes
The title of the preference.
type
"textfield" or "password" or "checkbox" or "dropdown"
Yes
The type of the preference.
value
unknown
No
The value of the preference.

PreferenceValues

Values of preference items.

Properties

Name
Type
Required
Description
[name: string]
any
Yes

Preferences

1
Preferences: Record<string, Preference>
Copied!
A record type holding the preferences (entered in Raycast Preferences) that have been passed to the command.
Last modified 7h ago