sdef

package
v0.1.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 17, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package sdef parses macOS scripting definition (sdef) XML and generates AppleScript runners from the parsed definitions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppName

func AppName(appPath string) string

AppName returns a short display name for an app path (e.g. "Xcode" from "/Applications/Xcode.app").

func BuildScript

func BuildScript(appName, cmdName, directParam string, params map[string]string) string

BuildScript constructs an AppleScript tell-block for a command invocation. appName is the AppleScript application name (e.g. "Xcode"). cmdName is the AppleScript command (e.g. "build"). params is a map of parameter-name → value string. directParam is the direct parameter value (empty string = omit).

func GetPropertyScript

func GetPropertyScript(appName, objectExpr, propName string) string

GetPropertyScript returns an AppleScript to get a property of the application.

func RunScript

func RunScript(script string) (string, error)

RunScript executes an AppleScript string via osascript and returns stdout.

func ToolName

func ToolName(appName, cmdName string) string

ToolName returns a safe MCP tool name for an app+command pair. e.g. appName="Xcode", cmdName="build" → "xcode_build"

Types

type Class

type Class struct {
	Name        string     `xml:"name,attr"`
	Code        string     `xml:"code,attr"`
	Description string     `xml:"description,attr"`
	Inherits    string     `xml:"inherits,attr"`
	Properties  []Property `xml:"property"`
	Elements    []Element  `xml:"element"`
}

Class is a scriptable object class.

type Command

type Command struct {
	Name            string      `xml:"name,attr"`
	Code            string      `xml:"code,attr"`
	Description     string      `xml:"description,attr"`
	Hidden          string      `xml:"hidden,attr"`
	DirectParameter *Parameter  `xml:"direct-parameter"`
	Parameters      []Parameter `xml:"parameter"`
	Result          *Result     `xml:"result"`
}

Command is a scriptable command.

type Dictionary

type Dictionary struct {
	Suites []Suite `xml:"suite"`
}

Dictionary is the top-level sdef document.

func Parse

func Parse(appPath string) (*Dictionary, error)

Parse runs sdef on appPath and returns the parsed Dictionary.

func (*Dictionary) Classes

func (d *Dictionary) Classes() []Class

Classes returns all classes across all suites.

func (*Dictionary) Commands

func (d *Dictionary) Commands() []Command

Commands returns all non-hidden commands across all suites.

type Element

type Element struct {
	Type   string `xml:"type,attr"`
	Access string `xml:"access,attr"`
}

Element is a child-element collection of a class.

type Parameter

type Parameter struct {
	Name        string `xml:"name,attr"`
	Code        string `xml:"code,attr"`
	Type        string `xml:"type,attr"`
	Optional    string `xml:"optional,attr"`
	Description string `xml:"description,attr"`
}

Parameter is a named command parameter.

type Property

type Property struct {
	Name        string `xml:"name,attr"`
	Code        string `xml:"code,attr"`
	Type        string `xml:"type,attr"`
	Access      string `xml:"access,attr"`
	Description string `xml:"description,attr"`
}

Property is a readable/writable attribute of a class.

type Result

type Result struct {
	Type        string `xml:"type,attr"`
	Description string `xml:"description,attr"`
}

Result describes the return type of a command.

type Suite

type Suite struct {
	Name        string    `xml:"name,attr"`
	Code        string    `xml:"code,attr"`
	Description string    `xml:"description,attr"`
	Commands    []Command `xml:"command"`
	Classes     []Class   `xml:"class"`
}

Suite groups related commands and classes.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL