// Name: HTTP Hello Trigger // Description: Starts a tiny HTTP server with an endpoint that opens a 'Hello' message in Script Kit. // Author: tayiorbeii // GitHub: tayiorbeii import "@johnlindquist/kit" import express from "express" import detectPort from "detect-port" const app = express() const port = await detectPort(3000) const url = `http://localhost:${port}` app.get("/", (req, res) => { res.send(`<h1>Script Kit HTTP Hello</h1><p><a href="/hello">Open "Hello" in Script Kit</a></p>`) }) app.get("/hello", async (req, res) => { void div(md(`# Hello`)) res.send(`Launched 'Hello' in Script Kit.`) }) await new Promise<void>(resolve => { app.listen(port, () => resolve()) open(url) }) await hide()// Name: HTTP Hello Trigger // Description: Uses Kit’s built-in HTTP server to trigger and display a 'Hello' message. // Author: tayiorbeii // GitHub: tayiorbeii // Access: public import "@johnlindquist/kit" // Core constants (typed for clarity and maintainability) const helloTitle: string = "Hello" const uiHtml: string = md(`# ${helloTitle}`) const responseBody: string = `Launched '${helloTitle}' in Script Kit.` const responseHeaders: Record<string, string> = { "Content-Type": "text/plain; charset=utf-8", "Cache-Control": "no-store", } // Respond to the HTTP request (when invoked via built-in server) // Note: Built-in server runs at http://localhost:3210 and maps /script-name to this script. // If not invoked via HTTP, sendResponse will simply be a no-op or can throw, so we guard it. try { await sendResponse(responseBody, responseHeaders) } catch (error) { // If we can't respond over HTTP (e.g., manual run), log and proceed to show the UI warn(`sendResponse failed: ${error instanceof Error ? error.message : String(error)}`) } // Show the UI message in Script Kit (await keeps the prompt open until dismissed) try { await div(uiHtml) } catch (error) { // Provide a fallback if the UI fails to render await notify(`Failed to display message: ${error instanceof Error ? error.message : String(error)}`) }