Examples

Examples

Save any of these in the Actions folder and switch it on.

Translate and type

Translate.py
#!/usr/bin/env python3
# @glimpse.description Say "translate into" and a language, then what to translate. Types the result.
# @glimpse.say translate into
# @glimpse.show insert
import subprocess, sys

spoken = sys.stdin.read().strip()
language, _, text = spoken.partition(",")
if not text:
    language, _, text = spoken.partition(" ")
language, text = language.strip(" .:"), text.strip()
if not text:
    sys.exit("Say a language, then what to translate.")

reply = subprocess.run(
    ["glimpse", "llm", f"Translate the text into {language}. Reply with only the translation, without naming the language.", "--local"],
    input=text, capture_output=True, text=True,
)
if reply.returncode:
    sys.exit(reply.stderr.strip() or "Translation failed")
print(reply.stdout.strip())

Ask, with answers from the web

Uses web search through OpenRouter when OPENROUTER_API_KEY is exported, and the model on this computer otherwise. Follow-up questions within ten minutes keep the earlier exchange. Set ASK_MODEL to pick the model.

Ask web.mjs
#!/usr/bin/env node
// @glimpse.description Answers a spoken question, from the web when an OpenRouter key is set.
// @glimpse.shortcut Control+Option+A
// @glimpse.timeout 60

import { execFileSync } from "node:child_process";
import { existsSync, readFileSync, statSync, writeFileSync } from "node:fs";

const question = readFileSync(0, "utf8").trim();
if (!question) process.exit(0);

const instructions = "Answer in at most three short sentences. Plain text, no Markdown.";
const key = process.env.OPENROUTER_API_KEY;

if (!key) {
  try {
    const answer = execFileSync("glimpse", ["llm", instructions, "--local"], {
      input: question,
      encoding: "utf8",
      stdio: "pipe",
    });
    console.log(answer.trim());
    process.exit(0);
  } catch (error) {
    console.error(String(error.stderr).trim() || error.message);
    process.exit(1);
  }
}

const historyFile = `${process.env.GLIMPSE_STATE_DIR}/history.json`;
const recent =
  existsSync(historyFile) && Date.now() - statSync(historyFile).mtimeMs < 10 * 60 * 1000;
const history = recent ? JSON.parse(readFileSync(historyFile, "utf8")) : [];
const input = [...history, { role: "user", content: question }];

const response = await fetch("https://openrouter.ai/api/v1/responses", {
  method: "POST",
  headers: { Authorization: `Bearer ${key}`, "Content-Type": "application/json" },
  body: JSON.stringify({
    model: process.env.ASK_MODEL ?? "openai/gpt-5.2",
    input: [{ role: "system", content: instructions }, ...input],
    tools: [{ type: "openrouter:web_search", parameters: { max_results: 3 } }],
  }),
});
if (!response.ok) {
  console.error(`${response.status} ${(await response.text()).slice(0, 200)}`);
  process.exit(1);
}

const data = await response.json();
const answer = data.output
  .filter((item) => item.type === "message")
  .at(-1)
  ?.content.find((part) => part.type === "output_text")
  ?.text.trim();
if (!answer) {
  console.error("No answer came back.");
  process.exit(1);
}

writeFileSync(historyFile, JSON.stringify([...input, { role: "assistant", content: answer }].slice(-6)));
console.log(answer);

Journal every dictation

Journal.sh
#!/bin/bash
# @glimpse.description Adds every dictation to today's journal.
# @glimpse.on dictation.saved
{ date '+%H:%M'; cat; echo; } >> ~/Documents/journal.md

Ask before posting

Standup.py
#!/usr/bin/env python3
# @glimpse.description Drafts your standup and asks before posting it.
# @glimpse.say post standup
import os, subprocess, sys

text = sys.stdin.read().strip()
subprocess.run(["glimpse", "toast", f"Drafting: {text}"], check=True)
answer = subprocess.run(
    ["glimpse", "ask", "Post it?", "--button", "Post", "--button", "Cancel"],
    capture_output=True, text=True,
).stdout.strip()
if answer != "Post":
    print("Not posted")
elif os.environ.get("GLIMPSE_HEADLESS") == "1":
    print("Would post")
else:
    # post `text` to your team chat here
    print("Posted")

Commit message from staged changes

Types a commit message for what's staged, using what you said as the intent. Scripts run in the Actions folder, so export PROJECT_DIR with your repository's path in your shell profile.

Commit.sh
#!/bin/bash
# @glimpse.description Writes a commit message for the staged changes.
# @glimpse.shortcut Control+Alt+M
# @glimpse.show insert
# @glimpse.timeout 60
intent=$(cat)
diff=$(git -C "${PROJECT_DIR:-$PWD}" diff --staged | head -c 4000)
[ -z "$diff" ] && { echo "Nothing is staged." >&2; exit 1; }
glimpse pill "Writing…"
printf 'Intent: %s\n\n%s' "$intent" "$diff" |
  glimpse llm "Write a one-line git commit message for this diff. Reply with only the message." --local

Open an app

On a shared key, the phrase picks the action, so one word is enough.

Open.sh
#!/bin/bash
# @glimpse.description Opens the app you name.
# @glimpse.shortcut Control+Alt+O
# @glimpse.say open
app=$(cat | sed 's/[.!?]*$//')
open -a "$app" || { echo "Couldn't find $app" >&2; exit 1; }

Grocery list

Groceries.py
#!/usr/bin/env python3
# @glimpse.description Keeps a grocery list. "Add to groceries milk and eggs."
# @glimpse.say add to groceries
import os, re, sys

items = [i.strip(" .") for i in re.split(r",| and ", sys.stdin.read().strip()) if i.strip(" .")]
path = os.path.join(os.environ["GLIMPSE_STATE_DIR"], "groceries.txt")
with open(path, "a") as f:
    f.writelines(f"{item}\n" for item in items)
print("Added " + ", ".join(items))

Meeting notes after a recording

Long recordings don't fit the model on this computer, so this uses the writing model from Settings.

Meeting notes.py
#!/usr/bin/env python3
# @glimpse.description Summarizes each finished Library recording into a notes file.
# @glimpse.on library.complete
# @glimpse.timeout 120
import os, subprocess, sys

transcript = sys.stdin.read()
summary = subprocess.run(
    ["glimpse", "llm", "Summarize this meeting in five bullet points, then list action items."],
    input=transcript, capture_output=True, text=True, check=True,
).stdout
with open(os.path.expanduser("~/Documents/meeting-notes.md"), "a") as f:
    f.write(f"\n## {os.environ.get('GLIMPSE_ID', '')}\n{summary}\n")
print("Meeting notes saved")

Where am I

A key that runs without a dictation.

Where.sh
#!/bin/bash
# @glimpse.description Shows the app you're in and how much text is selected.
# @glimpse.shortcut Control+Option+W
# @glimpse.listen false
printf 'App: %s\nSelected: %s characters' "${GLIMPSE_APP:-unknown}" "${#GLIMPSE_SELECTED_TEXT}"

One key to start and finish a recording

Record.py
#!/usr/bin/env python3
# @glimpse.description Starts a Library recording, or finishes the one that's running.
# @glimpse.shortcut Control+Option+R
# @glimpse.listen false
import json, subprocess

status = json.loads(subprocess.run(["glimpse", "record", "status", "--json"],
                                   capture_output=True, text=True).stdout or "{}")
verb = "start" if status.get("status", "idle") == "idle" else "finish"
subprocess.run(["glimpse", "record", verb], check=True, capture_output=True)
print("Recording" if verb == "start" else "Saved to Library")