hammerspoon2-docs
    Preparing search index...

    Function use

    • Load and configure a Spoon in one step, installing it first if it isn't installed yet - the built-in equivalent of Hammerspoon 1's SpoonInstall:andUse().

      If the Spoon is already installed, it's loaded and configured before use() returns, so hs.spoons.<name> can be used on the very next line, and nothing is downloaded. If it isn't installed and source is given, it's installed in the background (see hs.spoons.install()), then loaded and configured, and a notification says so; put anything that needs the Spoon in fn, or after the returned Promise resolves. An installed Spoon is never updated by use(): call hs.spoons.update() for that.

      path loads the Spoon from a directory of your own instead, as hs.spoons.load() does, for developing a Spoon: nothing is installed, and an installed copy is ignored. It takes precedence over source, ref and sha256, which are ignored while it's given, so a config can keep its source for everyone else and add path while you work on the Spoon.

      Configuration is applied after the Spoon is loaded (and its init() has run), in this order: each property of config is set on the Spoon's object, exactly as if you'd assigned it yourself, hotkeys is passed to its bindHotkeys() method, fn is called with the Spoon, and finally start() is called if start is true.

      The Promise rejects with an Error with a code, as hs.spoons.install()'s does, plus ENOTINSTALLED if the Spoon isn't installed and no source was given, or the error thrown by loading or configuring the Spoon.

      Parameters

      • name: string

        The name of the Spoon

      • Optionaloptions: {
            config?: Record<string, any>;
            disable?: boolean;
            fn?: (spoon: Object) => void;
            hotkeys?: "default" | Record<string, any>;
            path?: string;
            ref?: string;
            sha256?: string;
            source?: string;
            start?: boolean;
        }

        How to install, load and configure the Spoon

        • Optionalconfig?: Record<string, any>

          Properties to set on the Spoon's object; which ones it reads is up to the Spoon

        • Optionaldisable?: boolean

          true does nothing at all, which is easier than commenting the call out

        • Optionalfn?: (spoon: Object) => void

          Called with the Spoon after it's configured

        • Optionalhotkeys?: "default" | Record<string, any>

          Passed to the Spoon's bindHotkeys(), or "default" passes its defaultHotkeys

        • Optionalpath?: string

          A directory to load the Spoon from instead (relative to your config directory), as for hs.spoons.load(). Takes precedence over source, ref and sha256

        • Optionalref?: string

          The branch, tag or commit to install from, as for hs.spoons.install()

        • Optionalsha256?: string

          The expected SHA-256 of the download, as for hs.spoons.install()

        • Optionalsource?: string

          Where to install the Spoon from if it isn't installed, as for hs.spoons.install()

        • Optionalstart?: boolean

          true calls the Spoon's start() last

      Returns Promise<Object | null>

      Resolves with the Spoon once it's loaded and configured, or null if disable is true