A Lua module for macOS automation via ScriptingBridge, written in Zig.
local scrib = require("scrib")
-- Connect to an application by bundle ID
local chrome = scrib.app("com.google.Chrome")
print(chrome.name)
-- Access properties and collections
chrome.windows[1].activeTab.URL = "https://example.com"
-- Call methods
chrome:activate()
-- Error handling (returns nil + error string on failure)
local app, err = scrib.app("com.nonexistent.app")
if not app then
print("Error: " .. err)
endscrib bridges Lua and macOS applications through Apple's ScriptingBridge framework:
- ObjC Wrapping — ScriptingBridge objects are wrapped as Lua userdata with metatables that enable natural Lua syntax
- Dynamic Dispatch — Property access (
obj.name) and method calls (obj:activate()) are resolved at runtime via__index/__newindexmetamethods - Type Conversion — Lua types are automatically converted to/from ObjC equivalents (strings↔NSString, tables↔NSArray/CGRect, numbers↔NSNumber)
- Collection Indexing — Lua's 1-based indexing is translated to ObjC's 0-based arrays
- macOS
- Zig 0.15.0+
- Lua 5.4
zig buildThe library installs to zig-out/lib/scrib.so. Add this directory to your Lua package.cpath.
Validate:
lua -e 'package.cpath="zig-out/lib/?.so"; print(require("scrib").version())'# Unit tests
zig build test
# Integration tests (uses real macOS apps like Finder)
zig build integration