Load an installed Spoon by name. A Spoon must contain a well-formed spoon.json (with
non-empty name, author, version, and description fields) and an init.js, or
loading fails with an exception. init.js is loaded through the same require() used for
the rest of your config, so it can itself require() further files from within the
Spoon's own directory using relative paths. On success, the Spoon is also stored on
hs.spoons under its name, so other code can reach it without loading it again.
init.js must set module.exports to an object (or a function, since functions are
objects too) - loading fails with an exception otherwise. Its author, description,
and version properties are then set from spoon.json, overwriting any of the same
name the Spoon's own init.js set, so that information is always present and always
reflects what's on disk. If the resulting object has an init() method, it's called
automatically (with this bound to the object) before load() returns - matching
Hammerspoon 1's behavior. An exception thrown from init() fails the load: nothing is
stored on hs.spoons, and load() throws. Unlike init.js itself (which require()
only ever evaluates once), init() runs again on every load() 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 at init.js's top level instead.
The exception's code is ENOTINSTALLED if there's no such Spoon, EINVALIDARG if the name
can't be a Spoon's, or EINVALIDSPOON if the Spoon is malformed. An exception thrown by the
Spoon's own code is passed on as it is.
Parameters
name: string
The Spoon's name, matching its directory name under Spoons/
Returns Object
Whatever the Spoon's init.js assigned to module.exports
Throws
Throws an Error on failure; wrap calls in try/catch to handle it.
Load an installed Spoon by name. A Spoon must contain a well-formed
spoon.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 (or a function, since functions are objects too) - loading fails with an exception otherwise. Itsauthor,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. 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. The exception'scodeisENOTINSTALLEDif there's no such Spoon,EINVALIDARGif the name can't be a Spoon's, orEINVALIDSPOONif the Spoon is malformed. An exception thrown by the Spoon's own code is passed on as it is.