-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Intentify uses a WKWebView to run JavaScript, which is almost the same as Safari.
The biggest difference is that CORS is completely disabled in Intentify, allowing you to fetch anything without encountering errors.
Here is how Intentify is better than Run JavaScript for Mac Automation:
- Intentify runs a full-fledged JavaScript context, with Web APIs.
- Intentify can be used inline directly within Spotlight.
- Intentify can use html to render results and ask for input.
- Intentify supports asynchronous functions.
- Intentify runs pre-defined files, allowing you to use your favorite editor.
Here is how Intentify is better than Run JavaScript on Active Safari Tab:
- "Run JavaScript on Active Safari Tab" only works when you run the Shortcut inside Safari.
The simplest Intentify extension is a JavaScript snippet with a main function that returns a string.
function main(input) {
return input.toUpperCase();
}The input parameter is the text entered by the user in Spotlight, which is an empty string by default.
To handle async requests, just use an async function:
async function main(url) {
const response = await fetch(url);
const result = await response.text();
return result;
}To provide nicely rendered results, return an object like this:
function main(input) {
return {
title: '',
subtitle: '',
image: '', // base64 data or SF Symbol name
};
}You can also return an array to provide multiple responses.
So essentially, the method's signature looks like this:
type Result =
| string
| { title: string; subtitle?: string; image?: string; };
declare function main(input: string): Promise<Result | Result[] | undefined>;If the extension returns undefined, the input is passed to the next action.
You could also optionally provide a description and image using JSDoc comments:
/**
* Convert the input to uppercase.
*
* @image textformat
*/
function main(input) {
return input.toUpperCase();
}Intentify extracts them and displays them neatly in Spotlight.
Other valid tags are:
-
@displayName: String. Provides a human-readable display name that differs from the file name. Enclose the name in double quotes if it contains spaces. -
@showsDialog: Boolean. Whether to display a dialog showing the result. -
@avoidCopy: Boolean. By default, non-empty results are copied to the system pasteboard. Enabling this option prevents that behavior.
See the built-in examples to learn more.
Used to communicate with Foundation Models.
async function main(input) {
return await Intentify.askAI(input);
}Used to present a polished interface or prompt the user for input.
async function main(input) {
return await Intentify.renderUI(
`
<h1>Hello!</h1>
<button onclick="Intentify.returnValue({ title: 'Hi!', image: 'hands.clap' })">Return Value</button>
`,
{ title: 'What\'s up?', width: 480, height: 270 },
);
}Use Intentify.returnValue to continue execution with the specified Result described above.
Used to list all available extensions.
async function main(input) {
const extensions = await Intentify.listExtensions();
return JSON.stringify(extensions);
}Used to run another extension with name and input.
async function main() {
return await Intentify.runExtension('Apple Colors', 'Red');
}Used to run a system service with input.
async function main(input) {
return await Intentify.runService('Make Sticky', 'Hello') // Returns a boolean
}This allows you to run Shortcuts by enabling them in the services menu.
Check Intentify.d.ts for type definitions.
Since Intentify uses the App Intents framework, it can also be used in Shortcuts and work with other actions nicely.
For example, you can pre-fill the first parameter to quickly run an extension within Spotlight:
You can also use Intentify as a handy JavaScript engine by leveraging the built-in Eval JavaScript extension:
You might also want to check out this great tutorial: How To Use Spotlight Actions In macOS Tahoe.
- Sometimes, after invoking Intentify in Spotlight, the second text field is focused—this is a Spotlight bug.
- Sometimes, you must enter something into the second text field as the input—this is a Spotlight bug.