### Start the example documentation web server Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/hs.httpserver.hsminweb.html Initializes and starts the built-in documentation web server provided by the hs.doc module. ```lua require("hs.doc.hsdocs").start() ``` -------------------------------- ### hs.axuielement.observer:start Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.axuielement.observer.html Start observing the application. ```APIDOC ## hs.axuielement.observer:start ### Description Start observing the application and trigger callbacks for the elements and notifications assigned. ### Response - **observerObject** (object) - The observerObject. ``` -------------------------------- ### hs.application.watcher:start Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/hs.application.watcher.html Starts the application watcher instance. ```APIDOC ## Method hs.application.watcher:start ### Description Starts the application watcher. ### Returns - **watcher** (hs.application.watcher) - The hs.application.watcher object. ``` -------------------------------- ### hs.httpserver:start Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.httpserver.html Starts an HTTP server object. ```APIDOC ## hs.httpserver:start ### Description Starts an HTTP server object. ``` -------------------------------- ### Pathwatcher Lifecycle Example Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/getting-started.md Illustrates the importance of capturing objects returned by functions in variables to prevent them from being garbage collected prematurely. This example shows the correct way to start a pathwatcher. ```lua myWatcher = hs.pathwatcher.new(.....):start() ``` -------------------------------- ### hs.httpserver.hsminweb:start Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.httpserver.hsminweb.html Start serving pages for the hsminweb web server. ```APIDOC ## hs.httpserver.hsminweb:start ### Description Start serving pages for the hsminweb web server. ### Method POST ### Endpoint `hs.httpserver.hsminweb:start()` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "example": "hs.httpserver.hsminweb:start()" } ``` ### Response #### Success Response (200) - **hsminwebTable** (table) - The hsminWebTable object. #### Response Example ```json { "example": "hsminwebTable object" } ``` ``` -------------------------------- ### hs.fs.volume:start Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/hs.fs.volume.html Starts the volume watcher. ```APIDOC ## hs.fs.volume:start ### Description Starts the volume watcher. ### Response - **watcher** (hs.fs.volume) - An hs.fs.volume object ``` -------------------------------- ### Start Redshift Module Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.redshift.html Configures the schedule and starts the color adjustment module. ```lua hs.redshift.start(colorTemp,nightStart,nightEnd[,transition[,invertAtNight[,windowfilterDisable[,dayColorTemp]]]]) ``` -------------------------------- ### hs.network.configuration:start Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.network.configuration.html Starts monitoring the store object for changes to monitored keys and invokes a callback function if one is set. ```APIDOC ## start ### Description Starts watching the store object for changes to the monitored keys and invokes the callback function (if any) when a change occurs. ### Method `hs.network.configuration:start()` ### Parameters * None ### Returns * **storeObject** - The store object itself, allowing for chaining. ### Notes * The callback function should be specified with `hs.network.configuration:setCallback` and the keys to monitor should be specified with `hs.network.configuration:monitorKeys`. ``` -------------------------------- ### hs.window.highlight.start Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/hs.window.highlight.html Starts the window highlighting module. ```APIDOC ## hs.window.highlight.start ### Description Starts the module to begin highlighting the focused window. ### Method Function ### Parameters #### Path Parameters - **windowfilterIsolate** (hs.window.filter or list) - Optional - An hs.window.filter instance or list of app names that automatically enable "isolate" mode. - **windowfilterOverlay** (hs.window.filter) - Optional - An hs.window.filter instance that determines which windows to consider for "overlay" mode. ### Response - **None** ``` -------------------------------- ### hs.eventtap:start Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.eventtap.html Starts an event tap. ```APIDOC ## hs.eventtap:start ### Description Starts an event tap. ### Method Method ### Returns - **hs.eventtap** - The event tap object ``` -------------------------------- ### hs.wifi.watcher:start Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.wifi.watcher.html Starts the WiFi watcher to begin monitoring events. ```APIDOC ## hs.wifi.watcher:start ### Description Starts the SSID watcher to begin monitoring for configured WiFi events. ### Parameters - None ### Response - **watcher** (hs.wifi.watcher) - The watcher object. ``` -------------------------------- ### hs.audiodevice.watcher.start Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.audiodevice.watcher.html Starts the audio device watcher. ```APIDOC ## hs.audiodevice.watcher.start ### Description Starts the audio device watcher to begin monitoring for hardware events. ``` -------------------------------- ### Start Window Highlight Module Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.window.highlight.html Starts the hs.window.highlight module. Optionally accepts window filters to automatically enable 'isolate' mode for specific applications or windows. ```lua hs.window.highlight.start() ``` -------------------------------- ### Method: hs.spaces.watcher:start Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.spaces.watcher.html Starts the monitoring process for the Spaces watcher. ```APIDOC ## Method: hs.spaces.watcher:start ### Description Starts the Spaces watcher. ### Response - **watcher** (hs.spaces.watcher) - The watcher object. ``` -------------------------------- ### hs.axuielement.observer:start Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/hs.axuielement.observer.html Starts the observer, enabling it to watch for notifications and trigger callbacks. ```APIDOC ## hs.axuielement.observer:start ### Description Start observing the application and trigger callbacks for the elements and notifications assigned. ### Method `hs.axuielement.observer:start() -> observerObject` ### Parameters * None ### Returns * `observerObject` - The observer object. ### Notes This method does nothing if the observer is already running. ``` -------------------------------- ### hs.audiodevice:watcherStart Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.audiodevice.html Starts the watcher on an hs.audiodevice object. ```APIDOC ## hs.audiodevice:watcherStart ### Description Starts the watcher on an hs.audiodevice object. ### Method Method ### Returns - **hs.audiodevice or nil** - The hs.audiodevice object, or nil if an error occurred ``` -------------------------------- ### hs.pasteboard.watcher:start Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.pasteboard.watcher.html Starts the pasteboard watcher, enabling it to monitor for changes. ```APIDOC ## hs.pasteboard.watcher:start ### Description Starts an `hs.pasteboard.watcher` object. ### Method `hs.pasteboard.watcher:start() -> timer` ### Parameters * None ### Returns * **timer** - The `hs.pasteboard.watcher` object. ``` -------------------------------- ### hs.screen.watcher:start Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/hs.screen.watcher.html Starts the screen watcher, enabling the callback function to be invoked on screen changes. ```APIDIDOC ## hs.screen.watcher:start ### Description Starts the screen watcher, making it so fn is called each time the screen arrangement changes. ### Method Method ### Endpoint hs.screen.watcher:start() ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters * None ### Request Example ```lua watcher:start() ``` ### Response #### Success Response (200) * `watcher` (hs.screen.watcher) - The `hs.screen.watcher` object #### Response Example ```lua -- Returns the watcher object itself for chaining ``` ``` -------------------------------- ### Start Screensaver Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/_posts/2017-10-16-0.9.57.md Starts the screensaver. This function now works correctly under High Sierra. ```lua hs.caffeinate.startScreensaver() ``` -------------------------------- ### Example: Create and Print Text Marker Range Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.axuielement.axtextmarker.html Demonstrates creating an AXTextMarkerRange and printing the string content within that range using Safari as an example. This requires obtaining text markers from an application's accessibility elements. ```lua s = hs.axuielement.applicationElement(hs.application("Safari")) -- for a window displaying the DuckDuckGo main search page, this gets the -- primary display area. Other pages may vary and you should build your -- object as necessary for your target. c = s("AXMainWindow")("AXSections")[1].SectionObject[1][1] start = c("AXStartTextMarker") -- get the text marker for the start of this element ending = c("AXNextLineEndTextMarkerForTextMarker", start) -- get the next end of line marker print(c("AXStringForTextMarkerRange", hs.axuielement.axtextmarker.newRange(start, ending))) ``` -------------------------------- ### Load and Start ReloadConfiguration Spoon Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/getting-started.md This snippet loads the `ReloadConfiguration` Spoon and starts its functionality, enabling automatic configuration reloading. Ensure the Spoon is downloaded and placed in the `Spoons` directory. ```lua hs.loadSpoon("ReloadConfiguration") spoon.ReloadConfiguration:start() ``` -------------------------------- ### Get AXTextMarker Start Marker Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.axuielement.axtextmarker.html Returns the starting marker for an axTextMarkerRangeObject. This method is part of the axTextMarker object's interface. ```lua hs.axuielement.axtextmarker:startMarker() ``` -------------------------------- ### Start Active Window Layout Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.window.layout.html Starts a window layout in active mode, continuously enforcing its rules. Avoid multiple active layouts targeting the same windows. ```lua layout:start() ``` -------------------------------- ### Create and Use Window Switcher Instances Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.window.switcher.html Demonstrates how to create different types of window switcher instances with custom filters and bind them to hotkeys. Includes examples for default, space-specific, and browser-specific switchers. ```lua 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 :) ``` ```lua hs.hotkey.bind('alt','tab','Next window',function()switcher:next()end) hs.hotkey.bind('alt-shift','tab','Prev window',function()switcher:previous()end) ``` ```lua hs.hotkey.bind('alt','tab','Next window',hs.window.switcher.nextWindow) ``` ```lua hs.hotkey.bind('alt-shift','tab','Prev window',hs.window.switcher.previousWindow,nil,hs.window.switcher.previousWindow) ``` -------------------------------- ### Initialize hs.doc and access module documentation Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.doc.html Create a documentation object to browse module information directly from the console. ```lua doc = require("hs.doc") doc.hs.application ``` -------------------------------- ### Get Installed Audio Effect Names Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.sound.html Retrieves a table of all installed Audio Units Effect names. Useful for applying custom audio effects. ```lua hs.inspect(hs.audiounit.getAudioEffectNames()) ``` -------------------------------- ### Create and Configure a Toolbar Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.webview.toolbar.html Example of creating a new toolbar with various item types, enabling customization and autosaving, setting a default selected item, and defining a callback function for item actions. Use this to set up a functional toolbar for a webview or console. ```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) ``` -------------------------------- ### hs.httpserver.hsminweb:interface Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/hs.httpserver.hsminweb.html Get or set the network interface that the hsminweb web server will listen on. This must be set before the server starts. ```APIDOC ## GET/POST hs.httpserver.hsminweb:interface ### Description Get or set the network interface that the hsminweb web server will listen on. ### Method GET/POST ### Endpoint `hs.httpserver.hsminweb:interface([interface])` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **interface** (string | nil) - Optional - Specifies the network interface the web server will listen on. An explicit nil specifies that the web server should listen on all active interfaces. Defaults to nil. ### Request Example ```json { "interface": "en0" } ``` ### Response #### Success Response (200) - **current-value** (string | nil) - The current network interface setting. - **hsminwebTable** (object) - The hsminwebTable object if a parameter is provided. #### Response Example ```json { "current-value": null } ``` ``` -------------------------------- ### Get Font Families Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.styledtext.html Retrieves a list of all font families installed on the system. Useful for populating font selection menus. ```lua hs.styledtext.fontFamilies() ``` -------------------------------- ### hs.window.layout:start() Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.window.layout.html Activates a window layout instance, causing it to constantly monitor and enforce its defined rules. ```APIDOC ## hs.window.layout:start() ### Description Puts a window layout instance in "active mode". When active, the layout constantly monitors window filters for its rules and automatically re-applies them upon detecting changes. ### Method `start` ### Endpoint `hs.window.layout:start()` ### Parameters * None ### Returns * `hs.window.layout` object - The window layout object itself. ### Notes If a screen configuration is defined and not currently satisfied, the layout will be active but paused until requirements are met. Rules are enforced automatically without manual intervention via `apply()`. ``` -------------------------------- ### Get Number of Razer Devices Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.razer.html Retrieves the count of connected Razer devices. No setup is required beyond having devices connected. ```lua hs.razer.numDevices() ``` -------------------------------- ### Example Usage of backlightsCustom Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.razer.html Demonstrates how to use the `backlightsCustom` method with a specific color configuration for a device with multiple buttons. ```lua hs.razer.new(0):backlightsCustom({hs.drawing.color.red, nil, hs.drawing.color.green, hs.drawing.color.blue}) ``` -------------------------------- ### Get All Screens with hs.screen Source: https://context7.com/hammerspoon/hammerspoon.github.io/llms.txt Retrieve a list of all connected screens and iterate through them to print their index and name. Requires no special setup. ```lua -- Get all screens local screens = hs.screen.allScreens() for i, screen in ipairs(screens) do print(i, screen:name()) end ``` -------------------------------- ### hs.window.focusedWindow - Get Currently Focused Window Source: https://context7.com/hammerspoon/hammerspoon.github.io/llms.txt Returns the window object that currently has keyboard/mouse focus. This is the starting point for most window manipulation operations. ```APIDOC ## hs.window.focusedWindow ### Description Returns the window object that currently has keyboard/mouse focus. This is the starting point for most window manipulation operations. ### Method `hs.window.focusedWindow` ### Endpoint None ### Parameters None ### Request Example ```lua -- Get the focused window and display its title local win = hs.window.focusedWindow() if win then hs.alert.show("Focused: " .. win:title()) end -- Move focused window to the left half of the screen local win = hs.window.focusedWindow() if win then local screen = win:screen() local frame = screen:frame() win:setFrame({ x = frame.x, y = frame.y, w = frame.w / 2, h = frame.h }) end ``` ### Response #### Success Response (200) - **window object** (object) - The currently focused window. #### Response Example None ``` -------------------------------- ### Create and Configure a Modal Hotkey Environment Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.hotkey.modal.html Example of creating a new modal environment, defining entry and exit callbacks, and binding specific keys within that modal. Use this to set up custom shortcut modes. ```lua k = hs.hotkey.modal.new('cmd-shift', 'd') function k:entered() hs.alert'Entered mode' end function k:exited() hs.alert'Exited mode' end k:bind('', 'escape', function() k:exit() end) k:bind('', 'J', 'Pressed J',function() print'let the record show that J was pressed' end) ``` -------------------------------- ### Check for dismissed notifications Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/hs.notify.html Example of using `hs.notify.deliveredNotifications` with a timer to detect when a user dismisses a notification. This setup polls every 10 seconds. ```lua myNotification = hs.notify.new():send() clearCheck = hs.timer.doEvery(10, function() if not hs.fnutils.contains(hs.notify.deliveredNotifications(), myNotification) then if myNotification:activationType() == hs.notify.activationTypes.none then print("You dismissed me!") else print("A regular action occurred, so callback (if any) was invoked") end clearCheck:stop() -- either way, no need to keep polling clearCheck = nil end end) ``` -------------------------------- ### Get Grid Dimensions for a Screen Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.grid.html Retrieves the defined grid dimensions (columns and rows) for a specific screen or screen resolution. If no grid is set for the screen, the default grid is returned. Usage examples show how to get a grid for a specific resolution and how to modify the default grid's column count. ```lua hs.grid.getGrid(screen) -- Usage: local mygrid = hs.grid.getGrid('1920x1080') -- gets the defined grid for all screens with a 1920x1080 resolution local defgrid=hs.grid.getGrid() defgrid.w=defgrid.w+2 -- increases the number of columns in the default grid by 2 ``` -------------------------------- ### Configure and subscribe to window filters Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.window.filter.html Demonstrates how to create custom window filters, apply application-specific rules, and subscribe to window events. ```lua local wf=hs.window.filter -- alter the default windowfilter wf.default:setAppFilter('My IDE',{allowTitles=1}) -- ignore no-title windows (e.g. transient autocomplete suggestions) in My IDE -- set the exact scope of what you're interested in - see hs.window.filter:setAppFilter() wf_terminal = wf.new{'Terminal','iTerm2'} -- all visible terminal windows wf_timewaster = wf.new(false):setAppFilter('Safari',{allowTitles='reddit'}) -- any Safari windows with "reddit" anywhere in the title wf_leftscreen = wf.new{override={visible=true,fullscreen=false,allowScreens='-1,0',currentSpace=true}} -- all visible and non-fullscreen windows that are on the screen to the left of the primary screen in the current Space wf_editors_righthalf = wf.new{'TextEdit','Sublime Text','BBEdit'}:setRegions(hs.screen.primaryScreen():fromUnitRect'0.5,0/1,1') -- text editor windows that are on the right half of the primary screen wf_bigwindows = wf.new(function(w)return w:frame().area>3000000 end) -- only very large windows wf_notif = wf.new{['Notification Center']={allowRoles='AXNotificationCenterAlert'}} -- notification center alerts -- subscribe to events wf_terminal:subscribe(wf.windowFocused,some_fn) -- run a function whenever a terminal window is focused wf_timewaster:subscribe(wf.hasWindow,startAnnoyingMe):subscribe(wf.hasNoWindows,stopAnnoyingMe) -- fight procrastination :) ``` -------------------------------- ### hs.task:start Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.task.html Starts the execution of a task. If the task fails to start, an error message will be logged to the Hammerspoon Console. ```APIDOC ## hs.task:start ### Description Starts the task. ### Method `hs.task:start()` ### Parameters * None ### Returns * `hs.task` object if the task was started successfully; otherwise, `false`. ### Notes * If the task does not start successfully, the error message will be printed to the Hammerspoon Console. ``` -------------------------------- ### Configure and Bind hs.expose Instances Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.expose.html Create multiple expose instances with custom window filters and UI preferences, then bind them 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) ``` -------------------------------- ### Example Window Layout Command 2 Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.window.layout.html Divides the primary screen between the two newest windows and minimizes any others. ```text "1 new [0,0,50,100] 0,0 | 1 new [50,0,100,100] 0,0 | min" ``` -------------------------------- ### hs.distributednotifications:start Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.distributednotifications.html Starts the distributed notification watcher. ```APIDOC ## hs.distributednotifications:start ### Description Starts a NSDistributedNotificationCenter watcher. ### Response - **object** (hs.distributednotifications) - The hs.distributednotifications object ``` -------------------------------- ### hs.task:start Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/hs.task.html Starts the task. If the task fails to start, an error message will be printed to the Hammerspoon Console. Returns the task object on success or false otherwise. ```APIDOC ## hs.task:start ### Description Starts the task. ### Method `hs.task:start()` ### Parameters None ### Request Example ```json {} ``` ### Response #### Success Response (200) * **hs.task object | false** - The task object if the task was started successfully, otherwise false. #### Response Example ```json { "result": "hs.task object" } ``` ``` -------------------------------- ### Example Window Layout Command 1 Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.window.layout.html Moves the most recently focused window to the left third and tiles remaining windows on the right. ```text "move 1 foc [0,0,30,100] 0,0 | tile all foc [30,0,100,100] 0,0" ``` -------------------------------- ### Method: hs.timer.delayed:start Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/hs.timer.delayed.html Starts or restarts the callback countdown. ```APIDOC ## Method: hs.timer.delayed:start ### Description Starts or restarts the callback countdown. If a delay is provided, it sets the duration for this specific invocation only. ### Parameters - **delay** (number) - Optional - Countdown duration in seconds for this specific trigger. ### Response - **hs.timer.delayed object** - The delayed timer object. ``` -------------------------------- ### hs.ipc.cliInstall Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.ipc.html Installs the 'hs' command line tool to the specified path. ```APIDOC ## FUNCTION hs.ipc.cliInstall ### Description Installs the 'hs' command line tool. ### Parameters #### Arguments - **path** (string) - Optional - A path to install the tool in. Defaults to /usr/local - **silent** (boolean) - Optional - Whether or not to print errors to the Hammerspoon Console ### Response - **returns** (boolean) - true if the tool was successfully installed, otherwise false ``` -------------------------------- ### hs.network.reachability:start Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.network.reachability.html Starts watching the reachability object for changes. ```APIDOC ## hs.network.reachability:start ### Description Starts watching the reachability object for changes and invokes the callback function (if any) when a change occurs. ### Method Method ### Returns - **reachabilityObject** - the reachability object ``` -------------------------------- ### hs.window.highlight.start Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.window.highlight.html Starts the window highlighting module. Can be configured to automatically enable 'isolate' mode based on focused windows or applications. ```APIDOC ## hs.window.highlight.start ### Description Starts the module ### Method Function ### Signature hs.window.highlight.start([windowfilterIsolate[, windowfilterOverlay]]) ### Parameters #### Path Parameters * **windowfilterIsolate** (hs.window.filter or table) - Optional. An `hs.window.filter` instance that automatically enable "isolate" mode whenever one of the allowed windows is focused. Alternatively, a list of application names can be provided, and a windowfilter will be created for you. If omitted or nil, isolate mode won't be toggled automatically. * **windowfilterOverlay** (hs.window.filter) - Optional. An `hs.window.filter` instance that determines which windows to consider for "overlay" mode when focused. If omitted or nil, the default windowfilter will be used. ### Returns * None ### Notes * Overlay mode is disabled by default - see `hs.window.highlight.ui.overlayColor` ### Source [extensions/window/window_highlight.lua line 225](https://github.com/Hammerspoon/hammerspoon/blob/master/extensions/window/window_highlight.lua#L225) ``` -------------------------------- ### Constructor: hs.network.configuration.open Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.network.configuration.html Opens a session to the dynamic store maintained by the System Configuration server. ```APIDOC ## hs.network.configuration.open ### Description Opens a session to the dynamic store maintained by the System Configuration server. ### Method Constructor ### Returns - **storeObject** (object) - The opened store object. ``` -------------------------------- ### hs.doc.hsdocs.start Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.doc.hsdocs.html Start the Hammerspoon internal documentation web server. This is automatically called when hs.doc.hsdocs.help is invoked. ```APIDOC ## hs.doc.hsdocs.start ### Description Start the Hammerspoon internal documentation web server. ### Method POST ### Endpoint N/A (Lua function) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "example": "hs.doc.hsdocs.start()" } ``` ### Response #### Success Response (200) - **hs.doc.hsdocs** (table) - The table representing the `hs.doc.hsdocs` module. #### Response Example ```json { "example": "table: 0x..." } ``` ``` -------------------------------- ### Create and Bind Window Switcher Instances Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/hs.window.switcher.html Demonstrates creating different types of window switcher instances with custom filters and binding them to hotkeys. Requires at least one modifier key for hotkey binding. ```lua switcher = hs.window.switcher.new() switcher_space = hs.window.switcher.new(hs.window.filter.new():setCurrentSpace(true):setDefaultFilter{}) switcher_browsers = hs.window.switcher.new({'Safari','Google Chrome'}) hs.hotkey.bind('alt','tab','Next window',function()switcher:next()end) hs.hotkey.bind('alt-shift','tab','Prev window',function()switcher:previous()end) ``` -------------------------------- ### Method: hs.pathwatcher:start Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.pathwatcher.html Starts the monitoring process for a path watcher object. ```APIDOC ## Method: hs.pathwatcher:start ### Description Starts a path watcher. ### Parameters - None ### Response - **watcher** (hs.pathwatcher object) - The path watcher object. ``` -------------------------------- ### Define an access list for hs.httpserver Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.httpserver.hsminweb.html Example configuration showing how to accept a specific IP, reject a subnet, and accept all other remaining requests. ```lua { { 'X-Remote-Addr', '192.168.1.100', false, true }, -- accept requests from 192.168.1.100 { 'X-Remote-Addr', '^192%.168%.1%.', true, false }, -- reject all others from the 192.168.1 subnet { '*', '*', '*', true } -- accept all other requests } ``` -------------------------------- ### Select files or folders with hs.dialog.chooseFileOrFolder Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.dialog.html Displays a file and/or folder selection dialog. Optional parameters must be provided in the specified order. ```lua hs.inspect(hs.dialog.chooseFileOrFolder("Please select a file:", "~/Desktop", true, false, true, {"jpeg", "pdf"}, true)) ``` -------------------------------- ### GET hs.http.get Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.http.html Sends a synchronous HTTP GET request to a specified URL. ```APIDOC ## GET hs.http.get ### Description Sends an HTTP GET request to a URL. This function is synchronous and will block all other Lua execution while the request is in progress. ### Method GET ### Parameters #### Request Body - **url** (string) - Required - The URL to retrieve - **headers** (table) - Optional - String keys and values representing request headers ### Response - **status** (number) - HTTP response status - **body** (string) - Response body - **headers** (table) - Response headers ``` -------------------------------- ### Create and configure a new toolbar Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/hs.webview.toolbar.html Initializes a new toolbar with various item types and attaches it to the console. Requires setting autosaves and canCustomize to true to persist user changes. ```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:publish Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.bonjour.service.html Begin advertising the specified local service. ```APIDOC ## hs.bonjour.service:publish ### Description Begin advertising the specified local service. ### Parameters #### Path Parameters - **allowRename** (boolean) - Optional - Default true, specifies whether to automatically rename the service if a conflict occurs. - **callback** (function) - Optional - Callback function receiving the serviceObject and status (published or error). ### Response - **serviceObject** (userdata) - The serviceObject. ``` -------------------------------- ### GET hs.application.get Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.application.html Gets a specific running application based on a search hint. ```APIDOC ## GET hs.application.get ### Description Gets a running application based on a PID, bundle ID, or application name. ### Method GET ### Endpoint hs.application.get(hint) ### Parameters #### Query Parameters - **hint** (string/number) - Required - Search criterion (PID, bundle ID, or application name). ### Response #### Success Response (200) - **result** (hs.application object) - An hs.application object for a running application that matches the supplied search criterion, or nil if not found. ``` -------------------------------- ### hs.razer.init Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.razer.html Initializes the Razer driver and sets an initial discovery callback function. ```APIDOC ## hs.razer.init ### Description Initialises the Razer driver and sets a discovery callback. ### Method `hs.razer.init(fn)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters #### Path Parameters * **fn** (function) - Required - A function that will be called when a Razer device is connected or disconnected. It should take the following arguments: * A boolean, true if a device was connected, false if a device was disconnected * An hs.razer object, being the device that was connected/disconnected ### Request Example ```json { "example": "hs.razer.init(function(connected, device) print('Device event: ' .. device:name()) end)" } ``` ### Response #### Success Response (200) - None #### Response Example ```json { "example": "None" } ``` ### Notes * This function must be called before any other parts of this module are used ``` -------------------------------- ### hs.application.open Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.application.html Launches an application or activates it if it is already running. ```APIDOC ## hs.application.open ### Description Launches an application, or activates it if it's already running. ### Parameters #### Path Parameters - **app** (string) - Required - The application's name, full path, or bundle ID. - **wait** (number) - Optional - Maximum seconds to wait for launch. - **waitForFirstWindow** (boolean) - Optional - If true, wait until the app has spawned its first window. ### Response - **hs.application object** - The application object for the launched or activated application; nil if not found. ``` -------------------------------- ### Start a Distributed Notification Watcher Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/hs.distributednotifications.html Starts an existing `hs.distributednotifications` watcher to begin receiving notifications. ```lua hs.distributednotifications:start() ``` -------------------------------- ### hs.usb.watcher:start Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.usb.watcher.html Starts the USB watcher, enabling it to detect device connection and disconnection events. ```APIDOC ## hs.usb.watcher:start ### Description Starts the USB watcher. ### Method Method ### Endpoint hs.usb.watcher:start() ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```json { "example": "watcher:start()" } ``` ### Response #### Success Response (200) * watcher (hs.usb.watcher) - The hs.usb.watcher object #### Response Example ```json { "example": "watcher object" } ``` ``` -------------------------------- ### Start a Pasteboard Watcher Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.pasteboard.watcher.html Starts an existing hs.pasteboard.watcher object, enabling it to monitor pasteboard changes. ```lua hs.pasteboard.watcher:start() ``` -------------------------------- ### Create hs.expose Instance with Default Settings Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/hs.expose.html Creates a new hs.expose instance using the default windowfilter and no thumbnails. This is a basic setup for the expose functionality. ```lua expose = hs.expose.new(nil,{showThumbnails=false}) ``` -------------------------------- ### hs.noises:start Method Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.noises.html Starts the mouth noise listener, enabling it to process microphone input. ```APIDOC ## hs.noises:start ### Description Starts listening to the microphone and passing the audio to the recognizer. ### Method Method ### Endpoint hs.noises:start() ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters * None ### Returns * **self** (hs.noises) - The `hs.noises` object, allowing for chaining. ### Request Example ```lua local listener = hs.noises.new(function(event) print(event) end) listener:start() ``` ### Response #### Success Response (200) * **self** (hs.noises) - The `hs.noises` object. #### Response Example ```json { "self": "" } ``` ``` -------------------------------- ### Hint Hints for Focused Application - hs.hints.windowHints Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.hints.html Example of how to display hints only for windows belonging to the currently focused application. ```lua hs.hints.windowHints(hs.window.focusedWindow():application():allWindows()) ``` -------------------------------- ### Display Window Hints - hs.hints.windowHints Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.hints.html Displays keyboard hints for switching focus to windows. Optionally accepts a list of windows, a callback function, and a flag to include non-standard windows. ```lua hs.hints.windowHints([windows, callback, allowNonStandard]) ``` -------------------------------- ### hs.battery.watcher:start Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.battery.watcher.html Starts the battery watcher, enabling it to trigger the callback function on state changes. ```APIDOC ## hs.battery.watcher:start ### Description Starts the battery watcher. ### Method Method ### Endpoint hs.battery.watcher:start() ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Response #### Success Response (200) - **self** (hs.battery.watcher) - The hs.battery.watcher object. #### Response Example ```json { "example": "hs.battery.watcher" } ``` ``` -------------------------------- ### HTTP GET Request Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/hs.http.html Sends an HTTP GET request to a specified URL. This is a synchronous operation. ```APIDOC ## GET /url ### Description Sends an HTTP GET request to a URL. ### Method GET ### Endpoint `hs.http.get(url, headers)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```lua local status, body, headers = hs.http.get("http://example.com") ``` ### Response #### Success Response (200) - **status** (number) - The HTTP response status code. - **body** (string) - The response body content. - **headers** (table) - A table containing the response headers. #### Response Example ```json { "status": 200, "body": "...", "headers": { "Content-Type": "text/html" } } ``` ``` -------------------------------- ### hs.application.watcher:start and hs.application.watcher:stop Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.application.watcher.html Methods to control the application watcher, starting and stopping the monitoring of events. ```APIDOC ## Methods ### start Signature `hs.application.watcher:start()` Type Method Description Starts the application watcher Parameters * None Returns * The `hs.application.watcher` object ### stop Signature `hs.application.watcher:stop()` Type Method Description Stops the application watcher Parameters * None Returns * The `hs.application.watcher` object ``` -------------------------------- ### Implement a basic HTTP client with hs.socket Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.socket.html Demonstrates using socket tagging to handle HTTP headers and content asynchronously. Requires a connection to a host and specific read/write sequences. ```lua local TAG_HTTP_HEADER, TAG_HTTP_CONTENT = 1, 2 local body = "" local function httpCallback(data, tag) if tag == TAG_HTTP_HEADER then print(tag, "TAG_HTTP_HEADER"); print(data) local contentLength = data:match("\r\nContent%-Length: (%d+)\r\n") client:read(tonumber(contentLength), TAG_HTTP_CONTENT) elseif tag == TAG_HTTP_CONTENT then print(tag, "TAG_HTTP_CONTENT"); print(data) body = data end end client = hs.socket.new(httpCallback):connect("google.com", 80) client:write("GET /index.html HTTP/1.0\r\nHost: google.com\r\n\r\n") client:read("\r\n\r\n", TAG_HTTP_HEADER) ``` -------------------------------- ### Start a Pasteboard Watcher Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/hs.pasteboard.watcher.html Starts an existing hs.pasteboard.watcher object. This method is used to resume watching after the watcher has been stopped. ```lua watcher:start() ``` -------------------------------- ### hs.window.layout.new Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/hs.window.layout.html Creates a new hs.window.layout instance. ```APIDOC ## hs.window.layout.new ### Description Creates a new hs.window.layout instance. ### Parameters - **rules** (table) - Required - A table containing the rules for this windowlayout. If a special key 'screens' is present, its value must be a valid screen configuration. - **logname** (string) - Optional - Name of the hs.logger instance. - **loglevel** (number) - Optional - Log level for the hs.logger instance. ### Response - **hs.window.layout object** - A new windowlayout instance. ``` -------------------------------- ### hs.location.start() Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.location.html Initiates location tracking using the OS's Location Services. This enables registered callbacks to be triggered by location changes. ```APIDOC ## hs.location.start() ### Description Begins location tracking using OS X's Location Services so that registered callback functions can be invoked as the computer location changes. ### Method POST (conceptual) ### Endpoint N/A (Function call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```lua local success = hs.location.start() if success then print("Location tracking started.") else print("Failed to start location tracking.") end ``` ### Response #### Success Response (200) - **boolean** (boolean) - True if the operation succeeded, otherwise false. #### Response Example ```json true ``` ``` -------------------------------- ### Get Child Elements Count with Shortcut Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.axuielement.html Use the length operator `#` as a shortcut to get the number of child elements. ```lua #object ``` -------------------------------- ### Tangent Hub Status and Installation Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/hs.tangent.html Functions to check if the Tangent Hub software is installed and to check the connection state. ```APIDOC ## hs.tangent.isTangentHubInstalled ### Description Checks to see whether or not the Tangent Hub software is installed. ### Method Function ### Endpoint N/A (Lua Function) ### Parameters * None ### Returns * **boolean** - `true` if Tangent Hub is installed, otherwise `false`. ## hs.tangent.panelConnectionState ### Description Provides the connection state of a specific panel. ### Method Function ### Endpoint N/A (Lua Function) ### Parameters * **panelID** (string) - The ID of the panel as reported in the `InitiateComms` command. ### Returns * **state** (boolean) - The connected state of the panel, `true` if connected, `false` if disconnected. ``` -------------------------------- ### hs.spaces.toggleLaunchPad Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.spaces.html Toggles the Launch Pad display. ```APIDOC ## hs.spaces.toggleLaunchPad ### Description Toggles the Launch Pad display. ### Method `hs.spaces.toggleLaunchPad()` ### Parameters - None ### Returns - None ### Notes - This function provides the same functionality as the System Preferences -> Mission Control -> Hot Corners... -> Launch Pad setting, the Launch Pad touchbar icon, or the Launch Pad trackpad swipe gesture (Pinch with thumb and three fingers). ``` -------------------------------- ### hs.axuielement Module Overview Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/hs.axuielement.html Overview of how to interact with accessibility objects using shortcuts and formal methods. ```APIDOC ## hs.axuielement ### Description This module provides an interface to OS X accessibility objects. It allows for reading/writing attributes, iterating over children, and performing actions. ### Attribute Access - **object.attribute**: Shortcut for `object:attributeValue(attribute)` - **object.attribute = value**: Shortcut for `object:setAttributeValue(attribute, value)` ### Iteration - **pairs(object)**: Iterates over all attribute values. - **ipairs(object)**: Iterates over child elements (AXChildren). - **#object**: Returns the count of child elements. - **object[i]**: Accesses the i-th child element. ### Actions - **object:do()**: Shortcut for `object:performAction(action)` ### Parameterized Attributes - **object:WithParameter(value)**: Shortcut for `object:parameterizedAttributeValue(attribute, value)` ``` -------------------------------- ### hs.spoons.isInstalled Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.spoons.html 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 `hs.spoons.isInstalled(name)` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters * `name` - Name of the Spoon to check. ### Request Example None ### 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 None ``` -------------------------------- ### METHOD hs.network.ping.echoRequest:start Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.network.ping.echoRequest.html Starts the echoRequestObject by resolving the server's address and listening for ICMP Echo Reply packets. ```APIDOC ## METHOD hs.network.ping.echoRequest:start ### Description Start the echoRequestObject by resolving the server's address and start listening for ICMP Echo Reply packets. ### Method Method ### Parameters None ``` -------------------------------- ### hs.open Source: https://github.com/hammerspoon/hammerspoon.github.io/blob/master/docs/1.0.0/hs.html Opens a file with the default application, similar to the command line '/usr/bin/open'. ```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) - The path to a file/bundle to open. ### Returns * A boolean, true if the file was opened successfully, otherwise false. ``` -------------------------------- ### Launch or Focus Applications Source: https://context7.com/hammerspoon/hammerspoon.github.io/llms.txt Manages application state by launching or bringing existing instances to the foreground. Can be triggered via hotkeys or bundle identifiers. ```lua -- Launch or focus Safari hs.application.launchOrFocus("Safari") -- Launch by full path for disambiguation hs.application.launchOrFocus("/Applications/Google Chrome.app") -- Launch by bundle ID (more reliable) hs.application.launchOrFocusByBundleID("com.apple.Safari") -- Hotkey to quickly switch to common apps hs.hotkey.bind({"cmd", "alt"}, "S", function() hs.application.launchOrFocus("Safari") end) hs.hotkey.bind({"cmd", "alt"}, "T", function() hs.application.launchOrFocus("Terminal") end) -- Get frontmost application info local app = hs.application.frontmostApplication() hs.alert.show(app:name() .. " - " .. app:bundleID()) ```