docs » hs.spoons
Utility and management functions for Spoons Spoons are Lua plugins for Hammerspoon. See https://www.hammerspoon.org/Spoons/ for more information
- Functions - API calls offered directly by the extension
- bindHotkeysToSpec
- isInstalled
- isLoaded
- list
- newSpoon
- resourcePath
- scriptPath
- use
Signature | hs.spoons.bindHotkeysToSpec(def, map) -> none |
---|---|
Type | Function |
Description | Map a number of hotkeys according to a definition table |
Parameters |
|
Returns |
|
| Signature | hs.spoons.isInstalled(name) -> table | nil
|
| -----------------------------------------------------|---------------------------------------------------------------------------------------------------------|
| Type | Function |
| Description | Check if a given Spoon is installed. |
| Parameters |
- name - Name of the Spoon to check.
- If the Spoon is installed, it returns a table with the Spoon information as returned by
list()
. Returnsnil
if the Spoon is not installed.
| Signature | hs.spoons.isLoaded(name) -> boolean | nil
|
| -----------------------------------------------------|---------------------------------------------------------------------------------------------------------|
| Type | Function |
| Description | Check if a given Spoon is loaded. |
| Parameters |
- name - Name of the Spoon to check.
true
if the Spoon is loaded,nil
otherwise.
Signature | hs.spoons.list() -> table |
---|---|
Type | Function |
Description | Return a list of installed/loaded Spoons |
Parameters |
|
Returns |
|
| Signature | hs.spoons.newSpoon(name, basedir, metadata, [template]) -> string | nil
|
| -----------------------------------------------------|---------------------------------------------------------------------------------------------------------|
| Type | Function |
| Description | Create a skeleton for a new Spoon |
| Parameters |
- name: name of the new spoon, without the
.spoon
extension - basedir: (optional) directory where to create the template. Defaults to
~/.hammerspoon/Spoons
- metadata: (optional) table containing metadata values to be inserted in the template. Provided values are merged with the defaults. Defaults to:
{ version = "0.1", author = "Your Name <[email protected]>", homepage = "https://github.com/Hammerspoon/Spoons", license = "MIT - https://opensource.org/licenses/MIT", download_url = "https://github.com/Hammerspoon/Spoons/raw/master/Spoons/"..name..".spoon.zip" }
- template: (optional) absolute path of the template to use for the
init.lua
file of the new Spoon. Defaults to thetemplates/init.tpl
file included with Hammerspoon.
- The full directory path where the template was created, or
nil
if there was an error.
Signature | hs.spoons.resourcePath(partial) -> string |
---|---|
Type | Function |
Description | Return full path of an object within a spoon directory, given its partial path. |
Parameters |
|
Returns |
|
Signature | hs.spoons.scriptPath([n]) -> string |
---|---|
Type | Function |
Description | Return path of the current spoon. |
Parameters |
|
Returns |
|
| Signature | hs.spoons.use(name, arg, [noerror]) -> boolean | nil
|
| -----------------------------------------------------|---------------------------------------------------------------------------------------------------------|
| Type | Function |
| Description | Declaratively load and configure a Spoon |
| Parameters |
- name - the name of the Spoon to load (without the
.spoon
extension). - arg - if provided, can be used to specify the configuration of the Spoon. The following keys are recognized (all are optional):
- config - a table containing variables to be stored in the Spoon object to configure it. For example,
config = { answer = 42 }
will result inspoon.<LoadedSpoon>.answer
being set to 42. - hotkeys - a table containing hotkey bindings. If provided, will be passed as-is to the Spoon's
bindHotkeys()
method. The special string"default"
can be given to use the SpoonsdefaultHotkeys
variable, if it exists. - fn - a function which will be called with the freshly-loaded Spoon object as its first argument.
- loglevel - if the Spoon has a variable called
logger
, itssetLogLevel()
method will be called with this value. - start - if
true
, call the Spoon'sstart()
method after configuring everything else. - noerror - if
true
, don't log an error if the Spoon is not installed, simply returnnil
.
true
if the spoon was loaded,nil
otherwise