Hammerspoon Module Reference

New in version 0.0.8.

Control Hammerspoon using JXA-like syntax.

Classes:

XAHammerspoonApplication(properties)

A class for managing and interacting with Hammerspoon.app.

class PyXA.apps.Hammerspoon.XAHammerspoonApplication(properties)[source]

Bases: XASBApplication

A class for managing and interacting with Hammerspoon.app.

New in version 0.0.8.

Methods:

execute_lua_code(code)

Executes Lua code via Hammerspoon, with support for all Hammerspoon features.

Attributes:

frontmost

Whether Hammerspoon is the active application.

name

The name of the application.

version

The version of Hammerspoon.app.

execute_lua_code(code: str) Any[source]

Executes Lua code via Hammerspoon, with support for all Hammerspoon features.

Parameters:

code (str) – The Lua code to execute

Returns:

The Lua code execution result

Return type:

Any

Note

In order for this to work, you must add hs.allowAppleScript(true) to your Hammerspoon config.

Example:

>>> import PyXA
>>> app = PyXA.Application("hammerspoon")
>>> app.execute_lua_code("""
>>>     app = hs.appfinder.appFromName("Finder")
>>>     app:activate()
>>>     app:selectMenuItem({"Window", "Bring All to Front"})
>>> """)

New in version 0.0.8.

property frontmost: bool

Whether Hammerspoon is the active application.

property name: str

The name of the application.

property version: str

The version of Hammerspoon.app.