Hammerspoon API Reference (for Inspiration)
Hammerspoon is a powerful automation tool for macOS that allows users to interact with system APIs through Lua scripts. It provides extensive control over applications, windows, mouse, keyboard, file system, audio devices, battery, screen, clipboard, location services, Wi-Fi, and more.
The following APIs serve as a reference for potential future enhancements to Tego Bot, especially for macOS-specific features:
Core Modules
hs.application
Application management and control:
hs.application.applicationsForBundleID()- Get applications by bundle IDhs.application.launchOrFocus()- Launch or focus an applicationhs.application.launchOrFocusByBundleID()- Launch or focus by bundle IDhs.application:name()- Get application namehs.application:bundleID()- Get bundle identifierhs.application:isRunning()- Check if application is runninghs.application:kill()- Kill the applicationhs.application:kill9()- Force kill the applicationhs.application:activate()- Activate the applicationhs.application:hide()- Hide the applicationhs.application:unhide()- Unhide the applicationhs.application:isHidden()- Check if application is hiddenhs.application:allWindows()- Get all windows of the applicationhs.application:mainWindow()- Get main windowhs.application:focusedWindow()- Get focused windowhs.application:findMenuItem()- Find menu itemhs.application:selectMenuItem()- Select menu item
hs.window
Window management and manipulation:
hs.window.allWindows()- Get all windowshs.window.orderedWindows()- Get ordered windowshs.window.focusedWindow()- Get focused windowhs.window.find()- Find windows by title/applicationhs.window:title()- Get window titlehs.window:application()- Get window's applicationhs.window:frame()- Get window frame (position and size)hs.window:setFrame()- Set window framehs.window:size()- Get window sizehs.window:setSize()- Set window sizehs.window:topLeft()- Get top-left positionhs.window:setTopLeft()- Set top-left positionhs.window:center()- Center window on screenhs.window:move()- Move windowhs.window:resize()- Resize windowhs.window:minimize()- Minimize windowhs.window:unminimize()- Unminimize windowhs.window:isMinimized()- Check if minimizedhs.window:maximize()- Maximize windowhs.window:close()- Close windowhs.window:focus()- Focus windowhs.window:raise()- Raise window to fronths.window:setFullScreen()- Set fullscreen modehs.window:isFullScreen()- Check if fullscreenhs.window:setShadows()- Enable/disable shadowshs.window:zoomButtonRect()- Get zoom button rectanglehs.window:otherWindowsSameScreen()- Get other windows on same screenhs.window:otherWindowsAllScreens()- Get other windows on all screens
hs.mouse
Mouse control and monitoring:
hs.mouse.getAbsolutePosition()- Get absolute mouse positionhs.mouse.setAbsolutePosition()- Set absolute mouse positionhs.mouse.getRelativePosition()- Get relative position within screenhs.mouse.setRelativePosition()- Set relative position within screenhs.mouse.getButtons()- Get currently pressed mouse buttonshs.mouse.getCurrentScreen()- Get screen containing mousehs.mouse.trackingSpeed()- Get/set mouse tracking speedhs.mouse.scrollingDirection()- Get/set scrolling directionhs.mouse.click()- Simulate mouse clickhs.mouse.leftClick()- Simulate left clickhs.mouse.rightClick()- Simulate right clickhs.mouse.middleClick()- Simulate middle clickhs.mouse.scroll()- Simulate scroll wheelhs.mouse.doubleClick()- Simulate double clickhs.mouse.dragFromTo()- Drag from one point to another
hs.keycodes
Keyboard key code mapping:
hs.keycodes.map- Key code mapping tablehs.keycodes.getName()- Get key name from codehs.keycodes.getCode()- Get key code from namehs.keycodes.inputMethodChanged- Monitor input method changes
hs.eventtap
Low-level keyboard and mouse event monitoring and injection:
hs.eventtap.new()- Create new event taphs.eventtap:start()- Start event taphs.eventtap:stop()- Stop event taphs.eventtap.checkKeyboardModifiers()- Check modifier keyshs.eventtap.checkMouseButtons()- Check mouse buttonshs.eventtap.keyStroke()- Send keystrokehs.eventtap.keyStrokes()- Send multiple keystrokeshs.eventtap.keyRepeat()- Enable/disable key repeaths.eventtap.eventTypes- Event type constants
hs.screen
Screen/monitor management:
hs.screen.allScreens()- Get all screenshs.screen.primaryScreen()- Get primary screenhs.screen:frame()- Get screen framehs.screen:fullFrame()- Get full frame (including menu bar)hs.screen:availableFrame()- Get available frame (excluding dock/menu bar)hs.screen:name()- Get screen namehs.screen:id()- Get screen IDhs.screen:position()- Get screen positionhs.screen:setPrimary()- Set as primary screenhs.screen:setMode()- Set screen resolution/refresh ratehs.screen:currentMode()- Get current modehs.screen:availableModes()- Get available modeshs.screen:setBrightness()- Set brightnesshs.screen:getBrightness()- Get brightnesshs.screen:setGamma()- Set gamma correctionhs.screen:getGamma()- Get gamma correctionhs.screen:setInvertedPolarity()- Invert colorshs.screen:setTint()- Set color tint
hs.clipboard
Clipboard operations:
hs.clipboard.getContents()- Get clipboard contentshs.clipboard.setContents()- Set clipboard contentshs.clipboard.changeCount()- Get change counths.clipboard.readImage()- Read image from clipboardhs.clipboard.writeImage()- Write image to clipboardhs.clipboard.readStyledText()- Read styled texths.clipboard.writeStyledText()- Write styled texths.clipboard.readSound()- Read sound from clipboardhs.clipboard.writeSound()- Write sound to clipboardhs.clipboard.readURL()- Read URL from clipboardhs.clipboard.writeURL()- Write URL to clipboard
hs.fs
File system operations:
hs.fs.attributes()- Get file attributeshs.fs.chdir()- Change directoryhs.fs.currentDir()- Get current directoryhs.fs.dir()- List directory contentshs.fs.link()- Create symbolic/hard linkhs.fs.lock()- Lock filehs.fs.mkdir()- Create directoryhs.fs.remove()- Remove file/directoryhs.fs.rename()- Rename file/directoryhs.fs.rmdir()- Remove directoryhs.fs.touch()- Touch file (update timestamp)hs.fs.unlock()- Unlock filehs.fs.volumeInformation()- Get volume information
hs.pathwatcher
File system change monitoring:
hs.pathwatcher.new()- Create new path watcherhs.pathwatcher:start()- Start watchinghs.pathwatcher:stop()- Stop watching
hs.timer
Timer and scheduling:
hs.timer.doAfter()- Execute after delayhs.timer.doEvery()- Execute periodicallyhs.timer.doAt()- Execute at specific timehs.timer:start()- Start timerhs.timer:stop()- Stop timerhs.timer:running()- Check if runninghs.timer:nextTrigger()- Get next trigger time
hs.hotkey
Global hotkey bindings:
hs.hotkey.bind()- Bind hotkeyhs.hotkey.bindAll()- Bind all hotkeyshs.hotkey.unbindAll()- Unbind all hotkeyshs.hotkey:disable()- Disable hotkeyhs.hotkey:enable()- Enable hotkeyhs.hotkey:delete()- Delete hotkey
hs.chooser
Interactive chooser UI:
hs.chooser.new()- Create new chooserhs.chooser:show()- Show chooserhs.chooser:hide()- Hide chooserhs.chooser:query()- Set search queryhs.chooser:choices()- Set choiceshs.chooser:selectedRow()- Get selected row
hs.dialog
Dialog boxes:
hs.dialog.blockAlert()- Show blocking alerths.dialog.textPrompt()- Show text input dialoghs.dialog.webviewAlert()- Show webview alert
hs.webview
Web view component:
hs.webview.new()- Create new webviewhs.webview:url()- Get/set URLhs.webview:html()- Get/set HTML contenths.webview:reload()- Reload pagehs.webview:goBack()- Go backhs.webview:goForward()- Go forwardhs.webview:stopLoading()- Stop loadinghs.webview:show()- Show webviewhs.webview:hide()- Hide webview
hs.menubar
Menu bar item:
hs.menubar.new()- Create new menubar itemhs.menubar:setTitle()- Set titlehs.menubar:setIcon()- Set iconhs.menubar:setMenu()- Set menuhs.menubar:setClickCallback()- Set click callbackhs.menubar:delete()- Delete menubar item
hs.grid
Window grid management:
hs.grid.set()- Set window to grid positionhs.grid.get()- Get window grid positionhs.grid.snap()- Snap window to gridhs.grid.adjustWidth()- Adjust grid widthhs.grid.adjustHeight()- Adjust grid heighths.grid.show()- Show grid overlayhs.grid.hide()- Hide grid overlay
hs.layout
Window layout management:
hs.layout.apply()- Apply layouths.layout.get()- Get current layout
hs.battery
Battery information:
hs.battery.percentage()- Get battery percentagehs.battery.isCharging()- Check if charginghs.battery.isCharged()- Check if fully chargedhs.battery.timeRemaining()- Get time remaininghs.battery.timeToFullCharge()- Get time to full chargehs.battery.psuSerial()- Get power supply serialhs.battery.health()- Get battery healthhs.battery.healthCondition()- Get health conditionhs.battery.cycles()- Get charge cycleshs.battery.voltage()- Get voltagehs.battery.amperage()- Get amperagehs.battery.temperature()- Get temperaturehs.battery.maxCapacity()- Get max capacityhs.battery.designCapacity()- Get design capacity
hs.wifi
Wi-Fi information:
hs.wifi.currentNetwork()- Get current networkhs.wifi.interface()- Get Wi-Fi interfacehs.wifi.availableNetworks()- Get available networkshs.wifi.setPower()- Enable/disable Wi-Fihs.wifi.power()- Check if Wi-Fi is on
hs.location
Location services:
hs.location.get()- Get current locationhs.location.start()- Start location serviceshs.location.stop()- Stop location serviceshs.location.distance()- Calculate distance
hs.audiodevice
Audio device control:
hs.audiodevice.allDevices()- Get all audio deviceshs.audiodevice.defaultInputDevice()- Get default inpuths.audiodevice.defaultOutputDevice()- Get default outpuths.audiodevice:setDefaultInputDevice()- Set default inpuths.audiodevice:setDefaultOutputDevice()- Set default outpuths.audiodevice:volume()- Get/set volumehs.audiodevice:muted()- Get/set mute statehs.audiodevice:name()- Get device namehs.audiodevice:uid()- Get device UID
hs.caffeinate
System sleep/wake control:
hs.caffeinate.start()- Prevent system sleephs.caffeinate.stop()- Allow system sleephs.caffeinate.set()- Set caffeinate statehs.caffeinate.get()- Get caffeinate statehs.caffeinate.displaySleep()- Prevent display sleephs.caffeinate.systemSleep()- Prevent system sleephs.caffeinate.system()- Prevent system sleep
hs.notify
Notification system:
hs.notify.new()- Create new notificationhs.notify:send()- Send notificationhs.notify:withdraw()- Withdraw notificationhs.notify:title()- Set titlehs.notify:subTitle()- Set subtitlehs.notify:informativeText()- Set informative texths.notify:actionButtonTitle()- Set action buttonhs.notify:otherButtonTitle()- Set other buttonhs.notify:hasActionButton()- Check if has action buttonhs.notify:hasReplyButton()- Check if has reply buttonhs.notify:setIdImage()- Set ID imagehs.notify:setContentImage()- Set content imagehs.notify:setSoundName()- Set soundhs.notify:setAlwaysPresent()- Set always presenths.notify:setAutoWithdraw()- Set auto withdrawhs.notify:setWithdrawAfter()- Set withdraw delay
hs.http
HTTP requests:
hs.http.asyncGet()- Async GET requesths.http.asyncPost()- Async POST requesths.http.get()- Synchronous GET requesths.http.post()- Synchronous POST requesths.http.doRequest()- Generic HTTP requesths.http.urlParts()- Parse URLhs.http.encodeForQuery()- Encode for query stringhs.http.convertHtmlToText()- Convert HTML to text
hs.json
JSON operations:
hs.json.encode()- Encode to JSONhs.json.decode()- Decode from JSONhs.json.write()- Write JSON to filehs.json.read()- Read JSON from file
hs.socket
Network socket operations:
hs.socket.new()- Create new sockeths.socket:connect()- Connect to hosths.socket:disconnect()- Disconnecths.socket:write()- Write datahs.socket:read()- Read datahs.socket:listen()- Listen for connectionshs.socket:accept()- Accept connection
hs.uielement
UI element inspection:
hs.uielement.new()- Create UI elemenths.uielement:isValid()- Check if validhs.uielement:isApplication()- Check if applicationhs.uielement:isWindow()- Check if windowhs.uielement:title()- Get titlehs.uielement:role()- Get rolehs.uielement:selectedText()- Get selected texths.uielement:attributeValue()- Get attribute valuehs.uielement:setAttributeValue()- Set attribute valuehs.uielement:performAction()- Perform actionhs.uielement:elementAtPosition()- Get element at position
hs.image
Image operations:
hs.image.imageFromPath()- Load image from pathhs.image.imageFromASCII()- Create image from ASCIIhs.image:size()- Get image sizehs.image:setSize()- Set image sizehs.image:saveToFile()- Save to filehs.image:encodeAsPNG()- Encode as PNGhs.image:encodeAsJPEG()- Encode as JPEG
hs.screen.mainScreen
Main screen operations:
hs.screen.mainScreen()- Get main screenhs.screen:toEast()- Get screen to the easths.screen:toWest()- Get screen to the wesths.screen:toNorth()- Get screen to the northhs.screen:toSouth()- Get screen to the southhs.screen:next()- Get next screenhs.screen:previous()- Get previous screen
hs.spaces
Mission Control spaces:
hs.spaces.allSpaces()- Get all spaceshs.spaces.mainScreenSpaces()- Get main screen spaceshs.spaces.currentSpace()- Get current spacehs.spaces.moveWindowToSpace()- Move window to spacehs.spaces.gotoSpace()- Go to space
hs.fnutils
Functional utilities:
hs.fnutils.contains()- Check if containshs.fnutils.filter()- Filter arrayhs.fnutils.map()- Map arrayhs.fnutils.reduce()- Reduce arrayhs.fnutils.each()- Iterate arrayhs.fnutils.concat()- Concatenate arrayshs.fnutils.indexOf()- Find indexhs.fnutils.find()- Find elemenths.fnutils.sortByKeys()- Sort by keys
Spoons (Plugins)
Hammerspoon also supports a plugin system called "Spoons" that extends functionality:
- Window management Spoons: Window snapping, tiling, management
- Application Spoons: Application-specific automation
- Utility Spoons: Various utility functions
- UI Spoons: User interface enhancements
Notes
Hammerspoon is macOS-specific and provides deep integration with macOS system APIs. While Tego Bot focuses on cross-platform automation, many of these concepts (especially window management, screen operations, and system integration) could serve as inspiration for platform-specific enhancements or future cross-platform abstractions.
For more information, refer to the Hammerspoon official documentation.