The Spoon's name, matching its directory name under Spoons/. It's also the name it's stored under on hs.spoons.
Optionaloptions: { path?: string } | null
Where to load the Spoon from
Optionalpath?: stringA directory to load the Spoon from instead of Spoons/. A relative path is relative to your config directory, and ~ is your home directory.
Whatever the Spoon's init.js assigned to module.exports
Load an installed Spoon by name, or a Spoon from any directory with the
pathoption. A Spoon must contain a well-formedspoon.json(with non-emptyname,author,version, anddescriptionfields) and aninit.js, or loading fails with an exception.init.jsis loaded through the samerequire()used for the rest of your config, so it can itselfrequire()further files from within the Spoon's own directory using relative paths. On success, the Spoon is also stored onhs.spoonsunder its name, so other code can reach it without loading it again.init.jsmust setmodule.exportsto an object (not a function) - loading fails with an exception otherwise. Itsname,author,description, andversionproperties are then set fromspoon.json, overwriting any of the same name the Spoon's owninit.jsset, so that information is always present and always reflects what's on disk (a warning is logged ifspoon.json'snamedoesn't match the Spoon's directory name). If the resulting object has aninit()method, it's called automatically (withthisbound to the object) beforeload()returns - matching Hammerspoon 1's behavior. An exception thrown frominit()fails the load: nothing is stored onhs.spoons, andload()throws. Unlikeinit.jsitself (whichrequire()only ever evaluates once),init()runs again on everyload()call for the same Spoon, since the same cached object is returned each time - write it to be safe to call more than once, or do one-time setup atinit.js's top level instead.If the object has a
bindingsobject (its actions, keyed by name), it's given a genericbindHotkeys(mapping)beforeinit()runs, which binds the hotkeys inmapping(e.g.{ show: [["cmd", "alt"], "g"] }) to those actions, and anunbindHotkeys(actions)that unbinds them again. These replace anybindHotkeys()andunbindHotkeys()the Spoon exports itself. A Spoon withoutbindingskeeps its own, if it has them. See the Spoons guide for the details.If the object has a
shutdown()method, it's called (withthisbound to the object) just before your config is torn down, with"reload"or"quit", ashs.onShutdownis. Loaded Spoons are shut down newest first, afterhs.onShutdown.pathis for developing a Spoon: it loads the Spoon straight from that directory (such as a.spoon2bundle in your own checkout of its repository), instead of fromSpoons/, so reloading your config picks up your changes. Nothing is installed or copied, and a Spoon of the same name that's installed is ignored. A warning is logged each time, so a config that still points at a development copy doesn't go unnoticed.A Spoon whose
spoon.jsonhas aminimumHSVersionisn't loaded by an older Hammerspoon 2 (seehs.appinfo.version):init.jsisn't run, andload()throws, naming both versions.The exception's
codeisENOTINSTALLEDif there's no such Spoon,ENOTFOUNDifpathisn't a directory,EINVALIDARGif the name can't be a Spoon's or an option is malformed,EINVALIDSPOONif the Spoon is malformed, orEVERSIONif it needs a newer Hammerspoon 2. An exception thrown by the Spoon's own code is passed on as it is.