Skip to content
Public template

About

A template for publishing Hammerspoon 2 Spoons on GitHub, with linting, a generated README and docs

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

Hammerspoon 2 Spoon Template

A starting point for publishing your own Hammerspoon 2 Spoons on GitHub. It holds as many Spoons as you like, and comes with:

  • An example Spoon, Example.spoon2, with settings, hotkey actions, start(), stop() and shutdown(), to copy and make your own.
  • Linting: checks that each spoon.json is one Hammerspoon 2 will load, ESLint for the JavaScript, and rules that check each Spoon is structured the way Hammerspoon 2 expects. An optional type check against Hammerspoon 2's API catches misspelled functions.
  • A generated README: the list of Spoons below is written from the Spoons themselves, each time you push.
  • Generated docs: a page for each Spoon, with its settings, hotkey actions and methods, published to GitHub Pages.
  • Instructions for AI coding agents in AGENTS.md, with a skill for writing Spoons in .agents/skills.

If you haven't written a Spoon before, read the Spoons guide first: it covers what a Spoon is, how Hammerspoon 2 loads one, and the conventions they follow.

Using this template

  1. Click Use this template on GitHub to make your own repository from it.
  2. In your new repository's Settings:
    • Pages: set Source to GitHub Actions, so the docs workflow can publish.
    • Actions › General › Workflow permissions: choose Read and write permissions, so the README workflow can commit the updated README.
    • General: add the hammerspoon2-spoon topic, so your repository shows up in the list of Spoons on GitHub.
  3. Copy Example.spoon2 to YourSpoon.spoon2, change the name in its spoon.json to match, and write your Spoon. Delete Example.spoon2 when you no longer need it: the tooling doesn't depend on it, and the original stays in the template.
  4. Replace everything above the list of Spoons in this README with your own introduction.

Layout

YourSpoon.spoon2/        One directory per Spoon, at the top level or in Spoons/
  spoon.json             Its name, author, version and description
  init.js                Its code, starting with a /** */ comment that describes it
.github/workflows/       Lint, README and docs workflows
tools/                   The scripts those workflows run
schema/spoon.schema.json A JSON schema for spoon.json, for your editor
AGENTS.md                Instructions for AI coding agents

Each Spoon's init.js starts with a /** */ comment: a description of the Spoon, in Markdown, and an @example showing hs.spoons.use(). Each setting, hotkey action and method it exports has its own /** */ comment. These become the README's list of Spoons and the docs' pages, so there's nothing else to keep up to date. The README shows a Spoon's description up to its first heading (### ...), so reference material can go below one, and only appear in the docs. Leave source out of the examples: the README and docs add this repository's. See Example.spoon2/init.js for how it all looks.

Working on your Spoons

You'll need Node.js 22 or later. Then, in this directory:

npm install
npm run lint        # Check spoon.json files and the JavaScript
npm run typecheck   # Check the Spoons against Hammerspoon 2's API (downloads its types first)
npm run readme      # Update the list of Spoons in README.md
npm run docs        # Build the docs into _site/

To try a Spoon while you work on it, load it straight from your copy of this repository with path, rather than installing it:

hs.spoons.use("Example", {
    path: "~/src/my-spoons/Example.spoon2",
    hotkeys: "default",
    start: true,
})

When you release a new version of a Spoon, update the version in its spoon.json: that's how hs.spoons.update() knows there's something new. Tag your releases, so people can pin a version with ref.

Workflows

Workflow Runs on What it does
Lint Pull requests and pushes Checks the spoon.json files and the JavaScript. The type check runs too, but only warns, since it can complain about code that's fine.
README Pushes to main Regenerates the list of Spoons below, and commits it if it's changed.
Docs Pushes to main Builds the docs and publishes them to GitHub Pages.

The Spoons

📖 Read the documentation for all of these Spoons: every setting, hotkey action and method, with examples.

Spoon Version What it does
Example 1.0.0 Reminds you to take a break every so often.

Example

Shows a reminder to take a break every so often.

Once started, it shows an alert with message every interval minutes. The remind hotkey shows one straight away, and toggle starts or stops the reminders. When your config is reloaded, it remembers when the next reminder was due, so reloading doesn't restart the wait.

This is the template's example Spoon. Copy it, rename it and make it your own: it has the parts most Spoons have (settings, hotkey actions, start(), stop() and shutdown()), laid out the way this repository's README, docs and lint tooling expect.

hs.spoons.use("Example", {
    source: "Hammerspoon/Spoons2Template",
    hotkeys: "default",
    start: true,
})

// or, configured:
hs.spoons.use("Example", {
    source: "Hammerspoon/Spoons2Template",
    config: { message: "Stand up and stretch!", interval: 45 },
    hotkeys: { remind: [["cmd", "alt", "ctrl"], "b"] },
    start: true,
})

Documentation · Source · Needs Hammerspoon 2 1.0.0-beta.5 or later

About

A template for publishing Hammerspoon 2 Spoons on GitHub, with linting, a generated README and docs

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages