axcmd

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2026 License: MIT Imports: 9 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddPersistentFlags

func AddPersistentFlags(cmd *cobra.Command)

AddPersistentFlags registers the shared --json, --depth, and --limit persistent flags on cmd if they are not already defined.

func Commands

func Commands(opts ...Option) ([]*cobra.Command, error)

Commands constructs fresh Cobra subcommands for the selected subset. Each returned command can be added directly to any host Cobra command.

func NewAppsCommand

func NewAppsCommand() *cobra.Command

NewAppsCommand returns a Cobra command that lists running apps with bundle IDs.

func NewAttrCommand

func NewAttrCommand() *cobra.Command

NewAttrCommand returns a Cobra command that reads an AX attribute from the focused element or application root.

func NewClickCommand

func NewClickCommand() *cobra.Command

NewClickCommand returns a Cobra command that clicks an element by title.

func NewCommand

func NewCommand(opts ...Option) (*cobra.Command, error)

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

func NewFindCommand() *cobra.Command

NewFindCommand returns a Cobra command that finds AX elements by role/title.

func NewFocusCommand

func NewFocusCommand() *cobra.Command

NewFocusCommand returns a Cobra command that shows the currently focused element.

func NewMenuCommand

func NewMenuCommand() *cobra.Command

NewMenuCommand returns a Cobra command that clicks a menu item by path.

func NewPipeCommand

func NewPipeCommand() *cobra.Command

NewPipeCommand returns a Cobra command that executes an AX pipeline expression.

func NewTreeCommand

func NewTreeCommand() *cobra.Command

NewTreeCommand returns a Cobra command that prints an app's AX element tree.

func NewTypeCommand

func NewTypeCommand() *cobra.Command

NewTypeCommand returns a Cobra command that types text into an element.

Types

type Command

type Command string

Command identifies an embeddable ax subcommand.

const (
	CommandApps  Command = "apps"
	CommandTree  Command = "tree"
	CommandFind  Command = "find"
	CommandClick Command = "click"
	CommandType  Command = "type"
	CommandAttr  Command = "attr"
	CommandMenu  Command = "menu"
	CommandFocus Command = "focus"
	CommandPipe  Command = "pipe"
)

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

func ResolveCommands(opts ...Option) ([]Command, error)

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

func WithCommands(cmds ...Command) Option

WithCommands restricts the returned set to the named commands. If called multiple times, the lists are combined in order.

func WithExcludeCommands

func WithExcludeCommands(cmds ...Command) Option

WithExcludeCommands omits the named commands from the returned set.

func WithUse

func WithUse(use string) Option

WithUse overrides the root command Use string returned by NewCommand (default "ax").

Jump to

Keyboard shortcuts

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