Skip to content

AppleScript Automation ​

Otty is scriptable with AppleScript, so you can drive it from osascript, Automator, Shortcuts (via Run AppleScript), or any automation that already talks to a terminal. The dictionary is intentionally drop-in compatible with Terminal.app's most common verbs — most scripts written for Apple's Terminal work by changing the application name to "Otty".

There's nothing to install or enable: scripting ships in the app.

Availability

AppleScript support requires Otty 1.2.0 or later.

Running a command — do script ​

The core verb is do script. With no target it opens a new window and runs the command there, exactly like Terminal.app:

applescript
tell application "Otty"
    activate
    do script "cd ~/Projects/otty && cargo build"
end tell

Run in an existing window or tab by passing in:

applescript
tell application "Otty"
    do script "git status" in front window          -- the window's selected tab
    do script "npm test" in tab 2 of window 1
end tell

do script returns the tab it ran in, so you can keep a handle to it:

applescript
tell application "Otty"
    set buildTab to do script "make release"
    set custom title of buildTab to "Release Build"
end tell

Reading what's on screen ​

Each tab exposes its state as properties:

PropertyMeaning
contentsThe text currently visible on screen
historyThe full scrollback plus the visible screen
busytrue while a foreground process (not the shell) is running
processesNames of the processes running in the tab
ttyThe tty device path, e.g. /dev/ttys003
number of rows / number of columnsThe grid size
working directoryThe shell's current directory
idThe session id (also a selector for the otty CLI)
applescript
tell application "Otty"
    set t to do script "ls -la"
    delay 0.5
    return contents of t            -- grab the visible output
end tell

A common pattern — run a command, wait for it to finish, then read the result:

applescript
tell application "Otty"
    set t to do script "sleep 2; echo done"
    repeat while busy of t
        delay 0.2
    end repeat
    return history of t
end tell

Titles, selection, and windows ​

applescript
tell application "Otty"
    -- Rename a tab (pins the title against shell updates).
    set custom title of selected tab of front window to "Deploy"

    -- Restore the shell-provided title.
    set custom title of selected tab of front window to ""

    -- Bring a background tab forward.
    set selected of tab 3 of window 1 to true

    -- Standard window verbs work too.
    count windows
    get name of front window
end tell

Migrating from Terminal.app ​

Most Terminal scripts need only the application name changed:

applescript
-- Before
tell application "Terminal" to do script "uptime"

-- After
tell application "Otty" to do script "uptime"

The do script semantics, the tab object with contents / history / busy / processes / tty / custom title, and selected tab of a window all match Terminal.app's behavior.

Security ​

do script is allowed by default — automation should just work. To keep scripts from silently reading or driving sensitive panes, two guards apply:

  • SSH sessions and privileged (sudo) sessions are protected. do script into them is refused, and contents / history return empty.

This mirrors the same protection used by the otty CLI (pane send-keys / pane capture). If you intentionally want automation to reach remote or privileged panes, set in your config:

ipc-allow-sensitive-sessions = true

Prefer the shell?

If you script from a shell rather than AppleScript, the otty CLI covers the same ground — otty open, otty tab new, otty pane send-keys, and otty pane capture — and works cross-platform. Use the $OTTY_PANE_ID variable Otty exports into every pane to target the pane your script runs in (rather than the focused one) — see $TERM and Identification.

Otty