### hs.httpserver.hsminweb:start Source: https://www.hammerspoon.org/docs/hs.httpserver.hsminweb Starts the hsminweb web server, enabling it to serve pages. ```APIDOC ## POST /websites/hammerspoon/start ### Description Starts the hsminweb web server to begin serving pages. ### Method POST ### Endpoint /websites/hammerspoon/start ### Parameters *None* ### Response #### Success Response (200) - **message** (string) - Confirmation message that the server has started. #### Response Example ```json { "message": "Web server started successfully." } ``` ``` -------------------------------- ### Start hs.httpserver.hsminweb Server Source: https://www.hammerspoon.org/docs/hs.httpserver.hsminweb Starts the minimalist web server provided by the hs.httpserver.hsminweb module. After starting, the server can be accessed via a web browser at http://localhost:12345/. This function is part of the hs.doc.hsdocs module, which provides an example web site. ```lua require("hs.doc.hsdocs").start() ``` -------------------------------- ### hs.usb.watcher:start Source: https://www.hammerspoon.org/docs/hs.usb.watcher Starts the USB watcher, enabling it to detect device connection and disconnection events. ```APIDOC ## hs.usb.watcher:start ### Description Starts the USB watcher, enabling it to detect device connection and disconnection events. ### Method Method ### Endpoint N/A (Method on watcher object) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```lua watcher:start() ``` ### Response #### Success Response (200) - **watcher** (hs.usb.watcher) - The hs.usb.watcher object #### Response Example ```lua -- Returns the watcher object itself for chaining ``` ``` -------------------------------- ### start Source: https://www.hammerspoon.org/docs/hs.axuielement.observer Starts the accessibility observer, enabling it to trigger callbacks for assigned elements and notifications. This method does nothing if the observer is already running. ```APIDOC ## start ### Description Start observing the application and trigger callbacks for the elements and notifications assigned. ### Method `hs.axuielement.observer:start()` ### Parameters #### Path Parameters * None #### Query Parameters * None #### Request Body * None ### Request Example ```lua -- Assuming 'observer' is a valid hs.axuielement.observer object observer:start() ``` ### Response #### Success Response (200) * **observerObject** (`hs.axuielement.observer`) - The observer object itself. #### Response Example ```lua -- Returns the observer object if successful ``` ### Notes This method does nothing if the observer is already running. ``` -------------------------------- ### hs.location.start Source: https://www.hammerspoon.org/docs/hs.location Starts location tracking services. ```APIDOC ## POST /location/start ### Description Starts the Location Services for Hammerspoon, enabling more frequent location updates. ### Method POST ### Endpoint `/location/start` ### Parameters #### Path Parameters - None #### Query Parameters - None ### Request Example ```json { "example": "Not applicable for this function." } ``` ### Response #### Success Response (200) - **success** (boolean) - True if location tracking was started successfully. #### Response Example ```json { "success": true } ``` ### Notes - This function activates Location Services for Hammerspoon, so the first time you call this, you may be prompted to authorize Hammerspoon to use Location Services. ``` -------------------------------- ### Start Active Window Layout Source: https://www.hammerspoon.org/docs/hs.window.layout Starts an active window layout, continuously enforcing its rules. Avoid multiple active layouts targeting the same windows to prevent unpredictable results. ```lua layoutObject:start() ``` -------------------------------- ### Start Screensaver Source: https://www.hammerspoon.org/docs/hs.caffeinate This function requests the system to start the screensaver. This may also lock the screen if configured by the OS. ```APIDOC ## POST /websites/hammerspoon/caffeinate/startScreensaver ### Description Requests the system to start the screensaver. This may lock the screen if the OS is configured to do so. ### Method POST ### Endpoint /websites/hammerspoon/caffeinate/startScreensaver ### Parameters #### Request Body None ### Response #### Success Response (200) - **None** - This function does not return any value upon successful execution. ``` -------------------------------- ### Start Redshift with Window Filters and Hotkey Source: https://www.hammerspoon.org/docs/hs.redshift This snippet demonstrates how to configure and start the hs.redshift module. It includes creating a window filter to disable redshift for specific applications (VLC, Photos, login window), starting redshift with a specified color temperature and schedule, and binding a hotkey for manual inversion toggling. ```lua -- make a windowfilterDisable for redshift: VLC, Photos and screensaver/login window will disable color adjustment and inversion local wfRedshift=hs.window.filter.new({VLC={focused=true},Photos={focused=true},loginwindow={visible=true,allowRoles='*'}},'wf-redshift') -- start redshift: 2800K + inverted from 21 to 7, very long transition duration (19->23 and 5->9) hs.redshift.start(2800,'21:00','7:00','4h',true,wfRedshift) -- allow manual control of inverted colors hs.hotkey.bind(HYPER,'f1','Invert',hs.redshift.toggleInvert) ``` -------------------------------- ### Install Hammerspoon CLI Tool (Lua) Source: https://www.hammerspoon.org/docs/hs.ipc Installs the Hammerspoon command-line tool (`hs`) to a specified path. It can optionally run silently and may require manual creation of directories and permission adjustments. If installation fails, `hs.ipc.cliUninstall()` can be used to clean up. ```lua hs.ipc.cliInstall("/usr/local") -- or hs.ipc.cliInstall(nil, true) -- Installs to default path silently ``` -------------------------------- ### hs.network.ping.echoRequest:start Source: https://www.hammerspoon.org/docs/hs.network.ping.echoRequest Starts the echo request object by resolving the server's address and initiating the listening for ICMP Echo Reply packets. ```APIDOC ## hs.network.ping.echoRequest:start ### Description Start the echoRequestObject by resolving the server's address and start listening for ICMP Echo Reply packets. ### Method `start` ### Endpoint N/A (Method within an object) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```lua local echoRequest = hs.network.ping.newEchoRequest("example.com") echoRequest:start() ``` ### Response #### Success Response (200) * **echoRequestObject** (object) - The echoRequestObject itself. #### Response Example ```lua local echoRequest = hs.network.ping.newEchoRequest("example.com") local returnedObject = echoRequest:start() -- returnedObject is the same as echoRequest ``` ``` -------------------------------- ### Start Window Highlight Module (Lua) Source: https://www.hammerspoon.org/docs/hs.window.highlight This function starts the window highlighting module. It can optionally accept window filters to automatically enable 'isolate' mode for specific applications or windows, or to define which windows are considered for 'overlay' mode. ```lua hs.window.highlight.start() -- Example with application list for isolate mode hs.window.highlight.start({'Safari', 'iTerm'}) -- Example with window filter for isolate mode and overlay mode local isolateFilter = hs.window.filter.new() local overlayFilter = hs.window.filter.new() -- Add criteria to filters here... hs.window.highlight.start(isolateFilter, overlayFilter) ``` -------------------------------- ### Get Start Marker of AXTextMarkerRange Source: https://www.hammerspoon.org/docs/hs.axuielement.axtextmarker Retrieves the starting marker from an AXTextMarkerRange object. This allows access to the beginning of a defined text range. ```lua hs.axuielement.axtextmarker:startMarker() ``` -------------------------------- ### Create and Configure Toolbar - Lua Source: https://www.hammerspoon.org/docs/hs.webview.toolbar Demonstrates how to create a new toolbar with custom items, configure its behavior (customization, autosave), set a callback for item selection, and attach it to a window. This example showcases the primary usage of the hs.webview.toolbar module. ```lua t = require("hs.webview.toolbar") a = t.new("myConsole", { { id = "select1", selectable = true, image = hs.image.imageFromName("NSStatusAvailable") }, { id = "NSToolbarSpaceItem" }, { id = "select2", selectable = true, image = hs.image.imageFromName("NSStatusUnavailable") }, { id = "notShown", default = false, image = hs.image.imageFromName("NSBonjour") }, { id = "NSToolbarFlexibleSpaceItem" }, { id = "navGroup", label = "Navigation", groupMembers = { "navLeft", "navRight" }}, { id = "navLeft", image = hs.image.imageFromName("NSGoLeftTemplate"), allowedAlone = false }, { id = "navRight", image = hs.image.imageFromName("NSGoRightTemplate"), allowedAlone = false }, { id = "NSToolbarFlexibleSpaceItem" }, { id = "cust", label = "customize", fn = function(t, w, i) t:customizePanel() end, image = hs.image.imageFromName("NSAdvanced") } }):canCustomize(true) :autosaves(true) :selectedItem("select2") :setCallback(function(...) print("a", inspect(table.pack(...))) end) t.attachToolbar(a) ``` -------------------------------- ### hs.bonjour.service.new Constructor Source: https://www.hammerspoon.org/docs/hs.bonjour.service Creates a new service object for advertising a service provided by the local computer. ```APIDOC ## Constructor hs.bonjour.service.new ### Description Returns a new serviceObject for advertising a service provided by your computer. ### Signature `hs.bonjour.service.new(name, service, port, [domain]) -> serviceObject` ### Parameters - **name** (string) - The name of the service being advertised. If empty, the computer's hostname is used. - **service** (string) - A string specifying the service in the format `_service._protocol.` (e.g., `_http._tcp`). - **port** (integer) - The TCP or UDP port the service is provided at. - **domain** (string, optional) - The domain to advertise the service in. Defaults to 'local'. ### Returns - `serviceObject` - The newly created service object, or nil if an error occurred. ### Notes - If the specified name is not unique, a number will be appended to it after `publish` is called. - The service is not advertised until `hs.bonjour.service:publish` is invoked. - If `domain` is not specified, the default domain (usually 'local') is used. ``` -------------------------------- ### Get Installed Audio Effect Names (Lua) Source: https://www.hammerspoon.org/docs/hs.sound Retrieves a table of installed Audio Units Effect names. This function does not take any parameters and returns a Lua table containing the names. ```lua hs.sound.getAudioEffectNames() ``` -------------------------------- ### Get Host IP Address - Hammerspoon Lua Source: https://www.hammerspoon.org/docs/hs.network.ping.echoRequest Retrieves the IP address of the target host for an echo request. Returns a string if resolution is complete, false if pending, or nil if not started. This method is part of the hs.network.ping.echoRequest object. ```lua local ipAddress = echoRequest:hostAddress() if ipAddress == false then print("Address resolution in progress...") elif ipAddress then print("Host IP Address: " .. ipAddress) else print("Echo request not started.") end ``` -------------------------------- ### Open or Activate Application (Lua) Source: https://www.hammerspoon.org/docs/hs.application Launches an application if it's not running, or activates it if it is. Accepts the application name, full path, or bundle ID. Optional parameters allow waiting for the application to launch or its first window to appear. Be cautious with the 'wait' parameter as it blocks Hammerspoon activity. ```lua hs.application.open("com.apple.TextEdit") -- Opens TextEdit -- Opens Safari and waits up to 5 seconds for it to launch and show its first window local safariApp = hs.application.open("com.apple.Safari", 5, true) if safariApp then print("Safari opened and ready.") else print("Failed to open Safari within the time limit.") end ``` -------------------------------- ### hs.open Source: https://www.hammerspoon.org/docs/hs Opens a file or bundle using the default system application, similar to the `/usr/bin/open` command. ```APIDOC ## hs.open ### Description Opens a file as if it were opened with `/usr/bin/open`. ### Method `hs.open(filePath)` ### Parameters #### Path Parameters * **filePath** (string) - Required - A string containing the path to a file/bundle to open. ### Returns * **boolean** - true if the file was opened successfully, otherwise false. ``` -------------------------------- ### Get Host Address Family - Hammerspoon Lua Source: https://www.hammerspoon.org/docs/hs.network.ping.echoRequest Determines the IP address family (IPv4 or IPv6) currently used by an echo request object. Returns 'unresolved' if the object is not started or resolution is ongoing. This method is part of the hs.network.ping.echoRequest object. ```lua local family = echoRequest:hostAddressFamily() print("Host Address Family: " .. family) ``` -------------------------------- ### Get Phonetic Symbols (Lua) Source: https://www.hammerspoon.org/docs/hs.speech Returns an array of phonetic symbols recognized by the current synthesizer voice. This method is only supported by older Macintalk voices; modern voices or errors will result in `nil`. Each symbol entry includes its textual representation, opcode, an example word, and highlighting positions. ```lua local symbols = hs.speech:phoneticSymbols() if symbols then for _, symbolInfo in ipairs(symbols) do print(string.format("Symbol: %s, Example: %s", symbolInfo.Symbol, symbolInfo.Example)) end else print("Could not retrieve phonetic symbols.") end ``` -------------------------------- ### hs.help Source: https://www.hammerspoon.org/docs/hs Prints the documentation for a specified part of Hammerspoon's API or Lua 5.3. ```APIDOC ## hs.help ### Description Prints the documentation for some part of Hammerspoon's API and Lua 5.3. This function is actually sourced from hs.doc.help. ### Method `hs.help(identifier)` ### Endpoint N/A (Lua Function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```lua hs.help("hs.reload") ``` ### Response #### Success Response (200) None #### Response Example None ### Notes - This function is mainly for runtime API help while using Hammerspoon's Console. - You can also access the results of this function by the following methods from the console: - `help("identifier")` -- quotes are required, e.g. `help("hs.reload")` - `help.identifier.path` -- no quotes are required, e.g. `help.hs.reload` - Lua information can be accessed by using the `lua` prefix, rather than `hs`. - the identifier `lua._man` provides the table of contents for the Lua 5.3 manual. You can pull up a specific section of the lua manual by including the chapter (and subsection) like this: `lua._man._3_4_8`. - the identifier `lua._C` will provide information specifically about the Lua C API for use when developing modules which require external libraries. ``` -------------------------------- ### Set or Get History Size (Lua) Source: https://www.hammerspoon.org/docs/hs.logger Manages the size of the global log history. If a `size` is provided, it sets the maximum number of log entries to keep. If omitted, it returns the current history size. The default starting value is 0, which disables history logging. ```lua local currentSize = hs.logger.historySize() hs.logger.historySize(100) -- Set history size to 100 entries ``` -------------------------------- ### hs.spotlight:start Source: https://www.hammerspoon.org/docs/hs.spotlight Begin the gathering phase of a Spotlight query. This method initiates the search process. ```APIDOC ## POST /websites/hammerspoon/spotlight/start ### Description Begin the gathering phase of a Spotlight query. ### Method POST ### Endpoint /websites/hammerspoon/spotlight/start ### Parameters * None ### Response #### Success Response (200) - **spotlightObject** - The spotlight object. #### Response Example ```json { "status": "query started" } ``` ``` -------------------------------- ### Start Redshift Module with Custom Settings Source: https://www.hammerspoon.org/docs/hs.redshift The `hs.redshift.start` function initializes the Redshift module, setting the color temperature schedule and transition durations. It accepts parameters for night color temperature, start and end times, transition duration, inversion, window filters, and day color temperature. The function returns nothing. ```lua hs.redshift.start(colorTemp, nightStart, nightEnd, transition, invertAtNight, windowfilterDisable, dayColorTemp) ``` -------------------------------- ### Configure and Bind hs.expose Instances Source: https://www.hammerspoon.org/docs/hs.expose Demonstrates how to create and configure different instances of hs.expose with various settings, such as disabling thumbnails or focusing only on the active application. It then shows how to bind these instances to hotkeys for activation. ```lua -- set up your instance(s) expose = hs.expose.new(nil,{showThumbnails=false}) -- default windowfilter, no thumbnails expose_app = hs.expose.new(nil,{onlyActiveApplication=true}) -- show windows for the current application expose_space = hs.expose.new(nil,{includeOtherSpaces=false}) -- only windows in the current Mission Control Space expose_browsers = hs.expose.new({'Safari','Google Chrome'}) -- specialized expose using a custom windowfilter -- for your dozens of browser windows :) -- then bind to a hotkey hs.hotkey.bind('ctrl-cmd','e','Expose',function()expose:toggleShow()end) hs.hotkey.bind('ctrl-cmd-shift','e','App Expose',function()expose_app:toggleShow()end) ``` -------------------------------- ### AXTextMarker Start Marker Source: https://www.hammerspoon.org/docs/hs.axuielement.axtextmarker Retrieves the starting marker for an AXTextMarkerRange object. ```APIDOC ## `hs.axuielement.axtextmarker:startMarker()` ### Description Returns the starting marker for an axTextMarkerRangeObject. ### Method `startMarker()` ### Endpoint N/A (Function within an object) ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Request Example ```lua -- Assuming axTextMarkerRangeObject is a valid AXTextMarkerRange object local startMarker, err = axTextMarkerRangeObject:startMarker() if startMarker then print("Start marker retrieved.") else print("Error getting start marker: " .. err) end ``` ### Response #### Success Response (axTextMarkerObject | nil) - `axTextMarkerObject`: The starting marker of the range. - `nil`: If an error occurred. #### Response Example ```json -- Success: -- (axTextMarkerObject representation) -- Error: -- nil ``` ``` -------------------------------- ### hs.pathwatcher:start Source: https://www.hammerspoon.org/docs/hs.pathwatcher Starts the path watcher, enabling it to monitor the specified directory for changes. ```APIDOC ## hs.pathwatcher:start ### Description Starts the path watcher, initiating the monitoring of the directory for any file system modifications. ### Method Method ### Endpoint N/A (Lua method on a watcher object) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters * None ### Request Example ```lua myWatcher:start() ``` ### Response #### Success Response (200) * **watcher** (hs.pathwatcher) - The `hs.pathwatcher` object itself, allowing for method chaining. #### Response Example ```lua -- The watcher object is returned. ``` ``` -------------------------------- ### Create New Window Layout Instance Source: https://www.hammerspoon.org/docs/hs.window.layout Creates a new window layout instance with specified rules, an optional logger name, and log level. The rules table can include a 'screens' key for screen configuration. ```lua hs.window.layout.new(rules[, logname[, loglevel]]) ``` -------------------------------- ### hs.spoons.isInstalled Source: https://www.hammerspoon.org/docs/hs.spoons Checks if a given Spoon is installed. Returns a table with Spoon information if installed, otherwise returns nil. ```APIDOC ## hs.spoons.isInstalled ### Description Check if a given Spoon is installed. ### Method Call (Lua function) ### Endpoint N/A (Lua function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters * **name** (string) - Required - Name of the Spoon to check. ### Request Example ```lua -- Example usage: local spoonInfo = hs.spoons.isInstalled("MySpoon") if spoonInfo then print("MySpoon is installed.") else print("MySpoon is not installed.") end ``` ### Response #### Success Response (200) * **table | nil** - If the Spoon is installed, it returns a table with the Spoon information as returned by `list()`. Returns `nil` if the Spoon is not installed. #### Response Example ```json -- If installed: { "name": "MySpoon", "loaded": true, "version": "1.0.0" } -- If not installed: null ``` ``` -------------------------------- ### Start Screen Watcher (Lua) Source: https://www.hammerspoon.org/docs/hs.screen.watcher Starts an existing screen watcher object. Once started, the associated callback function will be invoked whenever a screen arrangement change is detected. This method returns the watcher object itself, allowing for method chaining. ```lua local watcher = hs.screen.watcher.new(function() print("Screen changed") end) watcher:start() ``` -------------------------------- ### Activate Application Window (Lua) Source: https://www.hammerspoon.org/docs/hs.application Attempts to bring an application's key window to the front and focus it. An optional boolean parameter can bring all of the application's windows forward. Returns true if activation was successful, false otherwise. This is useful for user-facing applications. ```lua local terminalApp = hs.application.get("Terminal") if terminalApp then local success = terminalApp:activate() if success then print("Terminal activated.") else print("Failed to activate Terminal.") end end ``` -------------------------------- ### hs.httpserver.hsminweb Constructors Source: https://www.hammerspoon.org/docs/hs.httpserver.hsminweb Provides constructors for creating new instances of the hs.httpserver.hsminweb server. ```APIDOC ## Constructors ### new #### Description Creates and returns a new `hs.httpserver.hsminweb` server object. #### Parameters * `options` (table, optional) - A table of options to configure the new server. See `hs.httpserver.hsminweb:new` for available options. #### Returns * `hs.httpserver.hsminweb` object - The newly created server object. ``` -------------------------------- ### Create a New hs.expose Instance Source: https://www.hammerspoon.org/docs/hs.expose This constructor creates a new hs.expose instance. It accepts an optional windowfilter to specify which windows should be displayed, and uiPrefs to customize the appearance and behavior. Additional optional parameters allow for custom logging. ```lua hs.expose.new([windowfilter[, uiPrefs][, logname, [loglevel]]]) -> hs.expose object ``` -------------------------------- ### hs.timer.new Source: https://www.hammerspoon.org/docs/hs.timer Creates a new `hs.timer` object for repeating interval callbacks. The timer does not start automatically and requires a call to its `:start()` method. ```APIDOC ## hs.timer.new ### Description Creates a new `hs.timer` object for repeating interval callbacks. ### Method Constructor ### Endpoint N/A (Lua function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```lua -- Example usage: local myTimer = hs.timer.new(2, function() hs.alert.show("Timer fired!") end) -- To start the timer: -- myTimer:start() ``` ### Response #### Success Response (200) - **timer** (`hs.timer`) - An `hs.timer` object #### Response Example ```lua -- An hs.timer object is returned, e.g.: -- myTimer ``` ### Notes - The returned object does not start its timer until its `:start()` method is called. - If `interval` is 0, the timer will not repeat. - For non-zero intervals, the lowest acceptable value is 0.00001s. ``` -------------------------------- ### hs.distributednotifications:start Source: https://www.hammerspoon.org/docs/hs.distributednotifications Starts a previously created NSDistributedNotificationCenter watcher. This method begins the process of listening for notifications. ```APIDOC ## POST /distributednotifications/{watcherId}/start ### Description Starts a NSDistributedNotificationCenter watcher. ### Method POST ### Endpoint /distributednotifications/{watcherId}/start ### Parameters #### Path Parameters - **watcherId** (string) - Required - The ID of the watcher to start. ### Request Example ```json { "watcherId": "unique_watcher_id_123" } ``` ### Response #### Success Response (200) - **object** (hs.distributednotifications) - The `hs.distributednotifications` object (the watcher). #### Response Example ```json { "watcherId": "unique_watcher_id_123" } ``` ``` -------------------------------- ### Start Speech Synthesis Source: https://www.hammerspoon.org/docs/hs.speech Initiates speech synthesis for the provided text using the system's default audio device. This method returns the synthesizer object, allowing for further control or chaining of operations. ```lua hs.speech:speak(textToSpeak) ``` -------------------------------- ### Create and Start a Path Watcher in Lua Source: https://www.hammerspoon.org/docs/hs.pathwatcher This snippet demonstrates how to create a new path watcher using `hs.pathwatcher.new` and then start it using the `start` method. The watcher is configured to monitor the Hammerspoon configuration directory and reload the configuration upon detecting changes. ```lua local myWatcher = hs.pathwatcher.new(os.getenv("HOME") .. "/.hammerspoon/", hs.reload):start() ``` -------------------------------- ### Get or Set Current Playback Time (Lua) Source: https://www.hammerspoon.org/docs/hs.sound Manages the current playback position of an hs.sound object. It can be used to get the current time or set a new seek time in seconds. Returns the sound object when setting and the time in seconds when getting. ```lua mySound:currentTime(5.0) -- Seek to 5 seconds local currentTime = mySound:currentTime() -- Get current time ``` -------------------------------- ### Move Window to Unit Rectangle (Lua) Source: https://www.hammerspoon.org/docs/hs.window Resizes and repositions the window to occupy a defined fractional area of the screen, specified by a unit rectangle. An optional duration can be set for animation. For example, `win:moveToUnit'[0.0,0.0,0.5,0.5]'` would make the window fill the top-left quarter of the screen. ```lua function moveToTopLeftQuarter(win) return win:moveToUnit'[0.0,0.0,0.5,0.5]' end ``` -------------------------------- ### hs.serial:open Source: https://www.hammerspoon.org/docs/hs.serial Opens the serial port, establishing a connection to the specified serial device. ```APIDOC ## hs.serial:open ### Description Opens the serial port. ### Method `hs.serial:open() -> serialPortObject | nil` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```lua local success = serialPort:open() if success then print("Serial port opened successfully.") else print("Failed to open serial port.") end ``` ### Response #### Success Response (200) - **serialPortObject** (serialPortObject) - The `hs.serial` object if the port was opened successfully. - **nil** - If the port could not be opened. #### Response Example ```lua -- Returns: serialPortObject -- or -- Returns: nil ``` ``` -------------------------------- ### Stop Active Window Layout Source: https://www.hammerspoon.org/docs/hs.window.layout Stops an active window layout, ceasing the continuous enforcement of its rules. This is typically used to deactivate a layout started with `hs.window.layout:start()`. ```lua layoutObject:stop() ``` -------------------------------- ### Get Console Content Source: https://www.hammerspoon.org/docs/hs.console Retrieve the text content of the Hammerspoon console output window. Optionally, get the content as a styledText object. ```APIDOC ## GET /console/getConsole ### Description Get the text content of the Hammerspoon console output window. By default, returns a plain string. If `styled` is true, returns an `hs.styledtext` object. ### Method GET ### Endpoint `/console/getConsole` ### Parameters #### Query Parameters - **styled** (boolean) - Optional. If true, returns a styledText object; otherwise, returns a plain string. Defaults to false. ### Response #### Success Response (200) - **content** (string | hs.styledtext) - The console text as a string or a styledText object, depending on the `styled` parameter. #### Response Example (string) ```json { "content": "Hello, Hammerspoon!" } ``` #### Response Example (styledText) ```json { "content": { "text": "Hello, Hammerspoon!", "attributes": [ { "type": "fontAttributes", "value": { "font": { "name": "Menlo", "size": 12 } }, "range": [0, 17] } ] } } ``` ``` -------------------------------- ### hs.httpserver.hsminweb Methods Source: https://www.hammerspoon.org/docs/hs.httpserver.hsminweb Provides methods for configuring and controlling the hs.httpserver.hsminweb server instance. ```APIDOC ## Methods ### accessList #### Description Gets or sets the access control list for the server. #### Parameters * `list` (table, optional) - A table defining the access control rules. #### Returns * `table` - The current access control list if no argument is provided. ### allowDirectory #### Description Gets or sets whether directory listings are allowed. #### Parameters * `allow` (boolean, optional) - `true` to allow directory listings, `false` otherwise. #### Returns * `boolean` - The current setting if no argument is provided. ### bonjour #### Description Gets or sets the Bonjour service name for the server. #### Parameters * `name` (string, optional) - The Bonjour service name. #### Returns * `string` - The current Bonjour service name if no argument is provided. ### cgiEnabled #### Description Gets or sets whether CGI is enabled for the server. #### Parameters * `enabled` (boolean, optional) - `true` to enable CGI, `false` otherwise. #### Returns * `boolean` - The current setting if no argument is provided. ### cgiExtensions #### Description Gets or sets the file extensions that are treated as CGI scripts. #### Parameters * `extensions` (table, optional) - A table of file extensions (e.g., `{".cgi", ".pl"}`). #### Returns * `table` - The current list of CGI extensions if no argument is provided. ### directoryIndex #### Description Gets or sets the default file to serve when a directory is requested. #### Parameters * `indexFile` (string, optional) - The name of the index file (e.g., `"index.html"`). #### Returns * `string` - The current directory index file if no argument is provided. ### dnsLookup #### Description Gets or sets whether DNS lookups are performed for incoming connections. #### Parameters * `lookup` (boolean, optional) - `true` to enable DNS lookups, `false` otherwise. #### Returns * `boolean` - The current setting if no argument is provided. ### documentRoot #### Description Gets or sets the root directory for serving static files. #### Parameters * `root` (string, optional) - The path to the document root directory. #### Returns * `string` - The current document root path if no argument is provided. ### interface #### Description Gets or sets the network interface the server listens on. #### Parameters * `iface` (string, optional) - The network interface name (e.g., `"0.0.0.0"` for all interfaces). #### Returns * `string` - The current network interface if no argument is provided. ### luaTemplateExtension #### Description Gets or sets the file extension for Lua template files. #### Parameters * `ext` (string, optional) - The file extension (e.g., `".ltpl"`). #### Returns * `string` - The current Lua template file extension if no argument is provided. ### maxBodySize #### Description Gets or sets the maximum allowed size for request bodies. #### Parameters * `size` (number, optional) - The maximum size in bytes. #### Returns * `number` - The current maximum body size if no argument is provided. ### name #### Description Gets or sets the name of the web server. #### Parameters * `name` (string, optional) - The name of the web server. #### Returns * `string` - The current server name if no argument is provided. ### password #### Description Gets or sets the password for basic authentication. #### Parameters * `password` (string, optional) - The password for authentication. #### Returns * `string` - The current password if no argument is provided. ### port #### Description Gets or sets the port the server listens on. #### Parameters * `port` (number, optional) - The port number. #### Returns * `number` - The current port number if no argument is provided. ### queryLogging #### Description Gets or sets whether to log incoming requests. #### Parameters * `log` (boolean, optional) - `true` to enable query logging, `false` otherwise. #### Returns * `boolean` - The current query logging setting if no argument is provided. ### scriptTimeout #### Description Gets or sets the timeout for executing dynamic scripts. #### Parameters * `timeout` (number, optional) - The timeout in seconds. #### Returns * `number` - The current script timeout if no argument is provided. ### ssl #### Description Gets or sets the SSL configuration for the server. #### Parameters * `config` (table, optional) - A table containing SSL configuration options (e.g., certificate and key paths). #### Returns * `table` - The current SSL configuration if no argument is provided. ### start #### Description Starts the web server. #### Returns * `boolean` - `true` if the server started successfully, `false` otherwise. ### stop #### Description Stops the web server. #### Returns * `boolean` - `true` if the server stopped successfully, `false` otherwise. ``` -------------------------------- ### hs.httpserver.new Source: https://www.hammerspoon.org/docs/hs.httpserver Creates a new HTTP or HTTPS server instance. The server can be configured to use SSL/TLS and advertise itself via Bonjour. ```APIDOC ## POST /websites/hammerspoon/hs.httpserver/new ### Description Creates a new HTTP or HTTPS server. ### Method POST ### Endpoint `/websites/hammerspoon/hs.httpserver/new` ### Parameters #### Query Parameters - **ssl** (boolean) - Optional - If true, the server will start using HTTPS. Defaults to false. - **bonjour** (boolean) - Optional - If true, the server will advertise itself with Bonjour. Defaults to true. Note that in order to change this, you must supply a true or false value for the `ssl` argument. ### Response #### Success Response (200) - **object** (hs.httpserver) - A new hs.httpserver object. ### Request Example ```json { "ssl": false, "bonjour": true } ``` ### Response Example ```json { "serverObject": "" } ``` ``` -------------------------------- ### Filter Windows by Application and Title (Lua) Source: https://www.hammerspoon.org/docs/hs.window.filter This example demonstrates how to create a window filter that targets specific applications and filters windows based on their titles. It shows how to ignore windows without titles for a given application and how to set up filters for specific applications with title patterns. ```lua local wf = hs.window.filter -- Ignore no-title windows (e.g., transient autocomplete suggestions) in 'My IDE' wf.default:setAppFilter('My IDE', { allowTitles = 1 }) -- Filter for any Safari windows with 'reddit' anywhere in the title local wf_timewaster = wf.new(false):setAppFilter('Safari', { allowTitles = 'reddit' }) -- Filter for notification center alerts local wf_notif = wf.new({ ['Notification Center'] = { allowRoles = 'AXNotificationCenterAlert' } }) ``` -------------------------------- ### Initialize and Bind hs.window.switcher in Lua Source: https://www.hammerspoon.org/docs/hs.window.switcher Demonstrates how to create new switcher instances with custom filters and bind them to hotkeys for navigating windows. It highlights the requirement for at least one modifier key for hotkey bindings and shows alternative direct calls to nextWindow/previousWindow. ```lua -- set up your windowfilter switcher = hs.window.switcher.new() -- default windowfilter: only visible windows, all Spaces switcher_space = hs.window.switcher.new(hs.window.filter.new():setCurrentSpace(true):setDefaultFilter{}) -- include minimized/hidden windows, current Space only switcher_browsers = hs.window.switcher.new{'Safari','Google Chrome'} -- specialized switcher for your dozens of browser windows :) -- bind to hotkeys; WARNING: at least one modifier key is required! hs.hotkey.bind('alt','tab','Next window',function()switcher:next()end) hs.hotkey.bind('alt-shift','tab','Prev window',function()switcher:previous()end) -- alternatively, call .nextWindow() or .previousWindow() directly (same as hs.window.switcher.new():next()) hs.hotkey.bind('alt','tab','Next window',hs.window.switcher.nextWindow) -- you can also bind to `repeatFn` for faster traversing hs.hotkey.bind('alt-shift','tab','Prev window',hs.window.switcher.previousWindow,nil,hs.window.switcher.previousWindow) ``` -------------------------------- ### Repeat Function Execution at Intervals (Lua) Source: https://www.hammerspoon.org/docs/hs.timer The `hs.timer.doEvery` function is a convenient shorthand for creating and starting a timer that repeatedly executes a given function at a specified interval in seconds. It is equivalent to `hs.timer.new(interval, fn):start()`. ```lua hs.timer.doEvery(interval, fn) -> timer ``` -------------------------------- ### hs.appfinder.appFromWindowTitlePattern Source: https://www.hammerspoon.org/docs/hs.appfinder Finds an application by Lua pattern in its window title. ```APIDOC ## hs.appfinder.appFromWindowTitlePattern ### Description Finds an application by Lua pattern in its window title (e.g."Inbox %(%d+ messages.*)"). ### Method Function ### Endpoint N/A (Lua function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```lua local inboxApp = hs.appfinder.appFromWindowTitlePattern("Inbox %(%d+ messages.*)") ``` ### Response #### Success Response - **app** (hs.application or nil) - An hs.application object if one can be found, otherwise nil #### Response Example ```lua -- Example of a returned hs.application object (structure not detailed here) -- nil if not found ``` ### Notes For more about Lua patterns, see http://lua-users.org/wiki/PatternsTutorial and http://www.lua.org/manual/5.2/manual.html#6.4.1 ``` -------------------------------- ### Start a Path Watcher Object in Lua Source: https://www.hammerspoon.org/docs/hs.pathwatcher This method is used to activate a previously created path watcher object. Once started, the watcher will begin monitoring the specified path for file system events. ```lua watcher:start() ``` -------------------------------- ### Location API - startTracking Source: https://www.hammerspoon.org/docs/hs.location Enables callbacks for location changes and refinements. This method may activate Location Services. ```APIDOC ## startTracking ### Description Enables callbacks for location changes and refinements for the current location object. This method may activate Location Services. ### Method `hs.location:startTracking()` ### Endpoint N/A (Lua method) ### Parameters #### Path Parameters * None #### Query Parameters * None #### Request Body * None ### Request Example ```lua local locationObject = hs.location:startTracking() if locationObject then print("Location tracking started.") -- You can now set up callbacks for location updates hs.location.setCallback(function(newLocation) print("Location updated: " .. newLocation.lat .. ", " .. newLocation.lon) end) else print("Failed to start location tracking. Location Services may be disabled.") end ``` ### Response #### Success Response * `locationObject` (object) - The location object. #### Response Example ```json { "__isLocationObject": true } ``` ### Notes * This function activates Location Services for Hammerspoon. You may be prompted to authorize Hammerspoon to use Location Services on the first call. ``` -------------------------------- ### Configure Interactive Grid Hints (Lua) Source: https://www.hammerspoon.org/docs/hs.grid Sets a custom grid layout and defines keyboard hints for the interactive resizing interface. This example demonstrates a 16x4 grid configuration, adjusting the `hs.grid.HINTS` table to match the grid dimensions for accurate visual feedback during interactive resizing. ```lua hs.grid.setGrid('16x4') hs.grid.HINTS={ {'f1', 'f2' , 'f3' , 'f4' , 'f5', 'f6', 'f7', 'f8', 'f9', 'f10', 'f11', 'f12', 'f13', 'f14', 'f15', 'f16'}, {'1' , 'f11', 'f15', 'f19', 'f3', '=' , ']' , '2' , '3' , '4' , '5' , '6' , '7' , '8' , '9' , '0' }, {'Q' , 'f12', 'f16', 'f20', 'f4', '-' , '[' , 'W' , 'E' , 'R' , 'T' , 'Y' , 'U' , 'I' , 'O' , 'P' }, {'A' , 'f13', 'f17', 'f1' , 'f5', 'f7', '\\', 'S' , 'D' , 'F' , 'G' , 'H' , 'J' , 'K' , 'L' , ',' }, {'X' , 'f14', 'f18', 'f2' , 'f6', 'f8', ';' , '/' , '.' , 'Z' , 'X' , 'C' , 'V' , 'B' , 'N' , 'M' } } ``` -------------------------------- ### hs.mouse.getCurrentScreen Source: https://www.hammerspoon.org/docs/hs.mouse Gets the screen the mouse pointer is on. ```APIDOC ## hs.mouse.getCurrentScreen ### Description Gets the screen the mouse pointer is on. ### Method GET ### Endpoint /mouse/getCurrentScreen ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example (No request body needed) ### Response #### Success Response (200) - **screen** (object or nil) - An `hs.screen` object that the mouse pointer is on, or nil if an error occurred. #### Response Example ```json { "screen": { "id": 1, "frame": {"x": 0, "y": 0, "w": 1920, "h": 1080} } } ``` ``` -------------------------------- ### List Running Applications (Lua) Source: https://www.hammerspoon.org/docs/hs.application Returns a list of all currently running applications on the system. Each item in the returned table is an `hs.application` object, providing access to further details about the running process. Returns an empty table if no applications are running. ```lua local runningApps = hs.application.runningApplications() print("Running Applications:") for _, app in ipairs(runningApps) do print("- " .. app:name() .. " (PID: " .. app:pid() .. ")") end ```