proxy ()įrom here, you can access attributes and call functions just like you would if you were dealing with To get started, create a LuaBridge instance and call proxy on it: bridge = LuaBridge () proxy = bridge. Which looks like interacting with normal objects. The proxy API hooks into many of Python's "dunder methods" like _getattr_ to provide an API If everything's set up correctly, then running the following in your shell should print Yay!: /Applications/Hammerspoon.app/Contents/Frameworks/hs/hs -c "'Yay'"Īfter all that, install this module with pip: pip install hammerspoon_bridge Your a (typically at ~/.hammerspoon/a) must contain this line somewhere:.Hammerspoon must be installed at /Applications/Hammerspoon.app.This is worryingly similar to eval, but across a programming language boundary.ĭo not use untrusted input when dealing with this bridge. Python accesses, calls, and indexes into Lua code, and then executing it by shelling out to These are not generated bindings, or a re-written like-for-like API. moveWindowToSpace ( window, newSpace ) hs. allSpaces () spacesOnScreen = allSpaces newSpace = spacesOnScreen # 1-indexed! This is bridging to Lua, after all. addSpaceToScreen ( screen, False ) allSpaces = hs. as first argument is equivalent to: window:screen() # (Which would be equivalent to: window.screen(window)) # Add space and get it hs. hs # Get focused window info window = hs. Switches to it: # Set up bridge from hammerspoon_bridge import LuaBridge hs = LuaBridge (). Say we wanted to write a script which creates a new space, moves the focused window to it, and Massive range of macOS automation tools readily available. This allows you to access seamlessly execute Hammerspoon functions from Python scripts, making its
0 Comments
Leave a Reply. |