Documentation
¶
Overview ¶
Package axcmd provides embeddable Cobra commands for macOS Accessibility API navigation, querying, and interaction.
Callers can mount the full command group or a chosen subset into any Cobra CLI without pulling in the MCP server or screenshot/OCR dependencies:
root := &cobra.Command{Use: "mycli"}
axRoot, err := axcmd.NewCommand(
axcmd.WithCommands(axcmd.CommandApps, axcmd.CommandTree, axcmd.CommandFind),
)
if err != nil {
return err
}
root.AddCommand(axRoot)
Individual subcommands can also be attached directly to an existing parent:
axcmd.AddPersistentFlags(root)
cmds, err := axcmd.Commands(axcmd.WithCommands(axcmd.ReadOnlyCommands()...))
if err != nil {
return err
}
root.AddCommand(cmds...)
Index ¶
- func AddPersistentFlags(cmd *cobra.Command)
- func Commands(opts ...Option) ([]*cobra.Command, error)
- func NewAppsCommand() *cobra.Command
- func NewAttrCommand() *cobra.Command
- func NewClickCommand() *cobra.Command
- func NewCommand(opts ...Option) (*cobra.Command, error)
- func NewFindCommand() *cobra.Command
- func NewFocusCommand() *cobra.Command
- func NewMenuCommand() *cobra.Command
- func NewPipeCommand() *cobra.Command
- func NewTreeCommand() *cobra.Command
- func NewTypeCommand() *cobra.Command
- type Command
- type Option
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AddPersistentFlags ¶
AddPersistentFlags registers the shared --json, --depth, and --limit persistent flags on cmd if they are not already defined.
func Commands ¶
Commands constructs fresh Cobra subcommands for the selected subset. Each returned command can be added directly to any host Cobra command.
func NewAppsCommand ¶
NewAppsCommand returns a Cobra command that lists running apps with bundle IDs.
func NewAttrCommand ¶
NewAttrCommand returns a Cobra command that reads an AX attribute from the focused element or application root.
func NewClickCommand ¶
NewClickCommand returns a Cobra command that clicks an element by title.
func NewCommand ¶
NewCommand constructs a fresh parent Cobra command (default Use: "ax") with shared persistent flags and the selected subcommands attached.
Example ¶
package main
import (
"fmt"
"github.com/spf13/cobra"
"github.com/tmc/axmcp/axcmd"
)
func main() {
host := &cobra.Command{Use: "mytool"}
axGroup, err := axcmd.NewCommand(
axcmd.WithCommands(axcmd.CommandApps, axcmd.CommandTree, axcmd.CommandFind),
)
if err != nil {
panic(err)
}
host.AddCommand(axGroup)
for _, c := range axGroup.Commands() {
fmt.Println(c.Name())
}
}
Output: apps find tree
func NewFindCommand ¶
NewFindCommand returns a Cobra command that finds AX elements by role/title.
func NewFocusCommand ¶
NewFocusCommand returns a Cobra command that shows the currently focused element.
func NewMenuCommand ¶
NewMenuCommand returns a Cobra command that clicks a menu item by path.
func NewPipeCommand ¶
NewPipeCommand returns a Cobra command that executes an AX pipeline expression.
func NewTreeCommand ¶
NewTreeCommand returns a Cobra command that prints an app's AX element tree.
func NewTypeCommand ¶
NewTypeCommand returns a Cobra command that types text into an element.
Types ¶
type Command ¶
type Command string
Command identifies an embeddable ax subcommand.
func AllCommands ¶
func AllCommands() []Command
AllCommands returns all available ax subcommands in canonical order.
func ReadOnlyCommands ¶
func ReadOnlyCommands() []Command
ReadOnlyCommands returns the non-mutating ax inspection subcommands.
func ResolveCommands ¶
ResolveCommands resolves the ordered list of commands selected by opts. It returns an error if any requested or excluded command name is unknown.
type Option ¶
type Option func(*config)
Option configures command selection and presentation for NewCommand and Commands.
func WithCommands ¶
WithCommands restricts the returned set to the named commands. If called multiple times, the lists are combined in order.
func WithExcludeCommands ¶
WithExcludeCommands omits the named commands from the returned set.