Trigger Scripts directly from Raycast

Since I use Raycast as my launcher on my computer I wanted a way to trigger Script Kit scripts directly from the Raycast menu without a second step. I made a script to generate Raycast shell scripts that will directly trigger the Script Kit scripts.

  1. Make a directory to store the Raycast scripts.
  2. Add this directory to the Raycast settings as a script directory.
  3. Run this script and choose that directory when prompted.

Just posting this as inspiration. This script is a little rough around the edges and could use refinement and customization to suit your needs.

Open generate-raycast-scripts in Script Kit

// Name: Generate Raycast Scripts
import "@johnlindquist/kit"
const collect = await npm("collect.js")
// get the directory to store the scripts in. Save in an environment variable
const directory = await env("RAYCAST_SCRIPTS_DIRECTORY", async () => { return await selectFolder("Select a directory to store the scripts in") })
// get all the scripts from Script Kit
let scripts = collect(await getScripts())
// remove preview from scripts
scripts = scripts.map(script => {
delete script.preview
return script
})
// get only kenv scripts
scripts = scripts.where('kenv', '')
// TODO find out which scripts should be ignored
// generate a script for each one in the directory
scripts.each(async script => {
const scriptContents = `#!/bin/bash
# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title ${script.name}
# @raycast.mode silent
# @raycast.packageName Script Kit Scripts
# Documentation:
# @raycast.description ${script.description}
~/.kit/kar ${script.command}
`
await writeFile(`${directory}/${script.name}.sh`, scriptContents, "utf-8")
})