hammerspoon2-docs
    Preparing search index...

    Namespace userdefaults

    Module for storing small amounts of data that persists across Hammerspoon restarts.

    Values are stored in a dedicated UserDefaults suite named "hs.userdefaults", kept separate from the app's own preferences so it doesn't get confused with Hammerspoon's own configuration when inspected with tools like the defaults command line utility.

    JavaScript ↔ storage type mapping:

    • JavaScript strings, numbers, booleans, arrays and objects round-trip directly
    • JavaScript Date objects round-trip directly (no special API required)
    • JavaScript null/undefined are not storable values; use clear() to remove a key

    Because the suite is just a standard macOS preferences domain, it can also be inspected and manipulated from the command line with the defaults tool:

    # Read every value stored by hs.userdefaults
    defaults read hs.userdefaults

    # Read a single key
    defaults read hs.userdefaults someKey

    # Write a value from the command line
    defaults write hs.userdefaults someKey "some value"

    # Delete a key
    defaults delete hs.userdefaults someKey
    clear
    get
    getKeys
    off
    on
    once
    set