Skip to content

Latest commit

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date

Repository files navigation

scrib

A Lua module for macOS automation via ScriptingBridge, written in Zig.

Usage

localscrib=require("scrib")
-- Connect to an application by bundle IDlocalchrome=scrib.app("com.google.Chrome")
print(chrome.name)
-- Access properties and collectionschrome.windows[1].activeTab.URL="https://example.com"-- Call methodschrome:activate()
-- Error handling (returns nil + error string on failure)localapp, err=scrib.app("com.nonexistent.app")
ifnotappthenprint("Error: " ..err)
end

How It Works

scrib bridges Lua and macOS applications through Apple's ScriptingBridge framework:

  1. ObjC Wrapping — ScriptingBridge objects are wrapped as Lua userdata with metatables that enable natural Lua syntax
  2. Dynamic Dispatch — Property access (obj.name) and method calls (obj:activate()) are resolved at runtime via __index/__newindex metamethods
  3. Type Conversion — Lua types are automatically converted to/from ObjC equivalents (strings↔NSString, tables↔NSArray/CGRect, numbers↔NSNumber)
  4. Collection Indexing — Lua's 1-based indexing is translated to ObjC's 0-based arrays

Requirements

  • macOS
  • Zig 0.15.0+
  • Lua 5.4

Building

zig build

The 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())'

Testing

# Unit tests
zig build test# Integration tests (uses real macOS apps like Finder)
zig build integration

License

MIT

About

Lua module for macOS automation via ScriptingBridge, written in Zig

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages