Stand-In TV

Stand-In TV: Test at Your Desk

Questions or trouble: support@psk-intellect.com.

Stand-In TV puts an Apple TV device that is somewhere else on your network on your desk: its live picture and its sound in a window on your Mac computer, and its remote in your keyboard, your trackpad, an on-screen remote, your voice and your scripts. It is made for people who make apps for the Apple TV device and want to test them without walking to a television.

What you need

The first time

Stand-In TV finds the Apple TV devices on your network by itself. The macOS operating system asks your permission for what Stand-In TV uses, each the first time it is needed:

Then pair the remote: click Pair under the picture. The TV shows a four-digit code; type it into the box Stand-In TV shows. That is done once for each TV; the pairing is kept in your keychain. If you have more than one TV, choose the one you want in the toolbar.

Setting up the picture

Done once for each TV:

  1. On the TV: Settings, Video and Audio, Audio Output: choose the TV's own speakers (or its receiver), not a HomePod. While the TV's sound goes to a HomePod, the macOS operating system offers that TV's picture to no app, the QuickTime Player app included.
  2. On the TV: Settings, Remotes and Devices, Remote App and Devices. Leave it on that screen.
  3. On this Mac computer, pair the Xcode app with the TV. In Terminal, with your TV's name as Stand-In TV's toolbar shows it: xcrun devicectl manage pair --device "Living Room". The TV shows a six-digit code; type it where Terminal asks for the pairing PIN. If the TV ends the pairing before showing a code, leave that screen on the TV, open it again, and run the line again.
  4. In Stand-In TV, choose the TV in the toolbar. The first time, the macOS operating system may show a box for a code the TV shows: type it there. The picture follows.

Pair and Pair Again under the picture pair only the remote; they do not set up the picture.

The picture and the sound

If the TV goes to sleep or the network blinks, Stand-In TV connects to it again by itself: it checks a quiet connection now and then, and tries a TV it cannot reach again after 2, 5 and 10 seconds, then every 30 seconds, for as long as that TV is chosen. To stop, choose None in the toolbar's list of TVs; Stand-In TV then connects to no TV, even when opened again, until you choose one.

The picture arrives as the TV draws it, at the TV's own size (usually 1920 by 1080). The window keeps the picture's shape as you resize it; View, then Actual Size, shows one of the TV's pixels on each of your screen's; Enter Full Screen fills the screen.

The sound is off each time Stand-In TV opens, so it never surprises you. Click the speaker in the toolbar (or Remote, then Play Sound from the TV) to hear the TV through this Mac computer.

Only one app at a time can show a TV's picture. If the QuickTime Player app is showing it, Stand-In TV says so; close the QuickTime Player app's recording window and click Try Again.

Keys, clicks and the trackpad

With the picture in front, these work as the TV's remote:

Arrow keysmove, as the clickpad's ring does
Return, or a click on the pictureselect: a click anywhere on the picture is the remote's Select, never a click on the spot under the pointer, because the TV has no pointer; move with the arrows or the clickpad first
Esc or Deleteback (the remote's Back button)
Spaceplay or pause
fn and Left Arrow (Home), or Shift-Command-Hthe TV button: Home
+ and −volume up and down: the TV's own volume and the sound you hear on this Mac computer move together, a step each (16 steps; held, they repeat); a script can read or set sound volume
Two fingers on the trackpada swipe on the remote's touch surface

A key held down is held on the remote too, so a long press works: hold Return to open an app's menu, hold Home for Control Center. Keys pressed with Command, Control or Option stay with your Mac computer, so every shortcut keeps working.

The on-screen remote (the remote button in the toolbar, or Option-Command-R) is laid out like the Apple TV device's remote: power, the clickpad (click its ring's edges to move, its middle to select, or swipe on it with two fingers), Back, the TV button, play or pause, volume, Control Center, the screen saver and the voice button. Its buttons are held for as long as you hold the mouse down.

The Remote menu has the rest: Control Center, the screen saver, wake and sleep, play, pause, skipping ten seconds ahead (Shift-Command-]) or back (Shift-Command-[), next, previous and the volume.

Typing into the TV

When the TV shows its keyboard (a search field, a name, a password), a field appears over the bottom of the picture and takes your typing at once. What you type goes to the TV as you type it, letter by letter, and you can paste. Press Return or Esc to give the keys back to the remote; click the field to type again.

Apps and links

Remote, then Apps, lists the apps on the TV; choose one to open it. Remote, then Open an App or a Link (Command-L), opens an app by its name or its bundle identifier, or opens a link that an app on the TV claims, so you can test your app's deep links (myapp://item/42) without building a way to reach them.

Remote, then Profiles, switches between the people on the TV.

Your voice

Click the microphone in the toolbar or on the on-screen remote (or Shift-Command-L); it turns red. Say what you want, and simply stop: Stand-In TV stops listening by itself when you pause, so there is no need to click again, and shows what it heard and what it did under the picture.

Stand-In TV hears you through the macOS operating system's own Dictation, on this Mac computer only. If Dictation is off, Stand-In TV says so and its button opens the Keyboard settings, where Dictation is turned on.

While the TV shows its keyboard, what you say is typed into it. Say "clear" to empty the field, "done" to select, or "go back" to leave it.

Your voice is recognized on this Mac computer by the macOS operating system's own speech recognition and is never sent anywhere. If this Mac computer cannot yet recognize your language by itself, Stand-In TV says so; turning Dictation on in System Settings, Keyboard, downloads what it needs.

Siri on the TV itself listens only to the TV's own remote, so Stand-In TV cannot pass your voice to Siri; it understands the commands above instead.

Your own words can do more: a script in the Scripts folder's Voice folder, named for a phrase, runs when you say it; a not-understood script is handed what Stand-In TV did not understand; and a voice script is handed every spoken command, the sound itself included, to pass to any program you choose. Scripting, below, says how.

Screenshots and recordings

File, then Show Screenshots or Show Recordings, opens their folders.

Scripting

Everything the remote does can be scripted, for repeatable tests, demonstrations and build steps; a script can read everything the window shows, wait for anything to change, and be called when something happens. There are several ways in, and one set of commands behind them all.

The commands

press select, down 3, press volume up 2a button, once or a number of times
hold home 1.5a long press, in seconds
swipe lefta swipe on the touch surface: up, down, left or right
type hello, set text "a b", clear textinto the field the TV is showing
open Settings, open com.example.myapp, open myapp://item/42an app by name or bundle identifier, or a link
play, pause, next, previous, skip 30, skip back 10what is playing
profile Alexswitch the TV's profile
screenshot, copy screenshot, record start, record stopsaved as from the File menu
sound on, sound offthe TV's sound on this Mac computer
wait 1.5a pause, in seconds
wait until keyboard, wait until text "Sign In" up to 30waits until it is so (ten seconds at most, unless up to says longer); fails, saying what is so instead, when it does not come
expect field "cats", expect text "Welcome"fails at once unless it is so: the checks of a test
read textthe words on the TV's screen now
log "signed in"a line of your own in the log
script "Smoke Test"runs one of your own scripts (below) and does what it prints
understand "down three"does what Stand-In TV would do if you said it
tv Officedrive the Apple TV device of that name, when there are several; waits until its remote connects

The buttons: up, down, left, right, select, back, home, play pause, volume up, volume down, screensaver, sleep, wake, channel up, channel down, guide, page up, page down, control center. Commands go one a line, or several on a line between semicolons; # starts a comment. A command that cannot be done stops the rest and says why, and what to do.

What a script can wait for and expect

keyboard, no keyboardthe TV's keyboard is up, or gone
field "TEXT"the TV's text field holds this (any case)
awake, asleep, idle, screensaverthe TV
connected, disconnected, picture, no picture, recording, not recordingStand-In TV itself
text "TEXT", no text "TEXT"the words on the screen, read on this Mac computer by the macOS operating system's own text recognition (any case, across lines)
still, still 3the picture has stopped changing (for a second, or as many as said): after a move, before a screenshot
changedthe picture has changed since the wait began
match "Home.png"the picture looks like a still you saved: a few small differences (a clock's digits, a word) are allowed, a moved focus or another screen is not; check words with text. A still is named by its file in Pictures, Stand-In TV (where Command-S saves), or by a path anywhere under Pictures.

A test of your own app, for example: open com.example.myapp; wait until text "Sign In"; select; wait until keyboard; type "tester@example.com"; expect field "tester@example.com"; select; wait until text "Welcome" up to 30; screenshot.

Run Commands, and your presses as commands

Scripts, then Run Commands (Command-K), runs commands you type, to try them out.

Scripts, then Record Presses as Commands (Option-Command-K), makes what you do into commands: your keys, swipes, typing, the on-screen remote and the menus, with the pauses between them as waits. Choose it again to stop, and the commands are in the Run Commands box to run again or change, and on the clipboard.

Your own scripts, and the Scripts menu

Stand-In TV runs scripts of your own from its scripts folder, which the macOS operating system keeps for it: Scripts, then Open Scripts Folder. Scripts, then Install Example Scripts, puts examples there (you choose the folder in the panel that opens; that is what lets Stand-In TV write there). A script is any file the system can run: a shell script, Python or another language with its #! line, made executable (chmod +x); an AppleScript; or an Automator workflow.

Whatever a script prints is done, as commands, one a line; whatever it writes to its error output goes to the log. So a script in any language answers back by printing. Each script is given its details as arguments and Stand-In TV's whole state, as JSON, on its input (an AppleScript or a workflow gets the same as items, the JSON last). Examples whose names end in .example do nothing until you rename them without it.

Events

connectionthe remote's connection: connected, connecting, searching, not paired, pairing, lost or failed (with why)
powerthe TV woke, slept, went idle or started its screen saver
keyboardthe TV's keyboard came up (with what its field holds), or went away
picturethe picture began arriving, or stopped (with why)
recordingstarted, saved (with the movie's path), or not saved (with why)
screenshota screenshot was saved (its path)
hearda spoken command was heard (what was heard)
not-understooda spoken command Stand-In TV did not understand: what the script prints is done instead
problemsomething went wrong: what, and what to do about it
tvanother Apple TV device was chosen
every-eventall of the above, the event's name first
voicenot an event: when it is there, it reads every spoken command itself, given the words this Mac computer heard and the sound itself (a WAV file) on its input, even when no words were heard. What it prints is done; understand "WORDS" hands back what it leaves to Stand-In TV. Pass the sound to any program you like.

A keyboard script that prints type "tester@example.com" fills in every empty field the TV shows; a problem script can send you word wherever you are. Each event's script runs one at a time, in order; one that is still running when its event comes again is run again after it. Commands that a script prints, which set off events of their own, are followed three deep and no deeper, so a script cannot set itself off without end. Scripts, then Event Scripts, shows which are in place.

AppleScript

Stand-In TV has an AppleScript dictionary (in the Script Editor app, File, then Open Dictionary). For example:

tell application "Stand-In TV"
    run command "open Settings; wait until still; down 2"
    press "select" times 1
    send text "stand-in" replacing true
    open on tv "myapp://item/42"
    set shot to save screenshot      -- the file's path
    if keyboard showing then send text "hello"
    set words to read text           -- the screen's words, a line each
    get {tv name, connection state, power state, keyboard text, message}
    set answer to run command "expect text \"Welcome\"" with json
end tell

The commands: run command (with json, it answers {"ok": true, "done": [...]}, or {"ok": false, "done": [...], "error": "..."} when a command could not be done, rather than failing; it still fails if Stand-In TV is not ready to take commands), press (with times or holding for), swipe, send text (with replacing), open on tv, save screenshot, start recording, stop recording, list apps and read text. The properties: connected, connection state, tv name, tv names, power state, keyboard showing, keyboard text, picture showing, picture width, picture height, sound on, sound volume (0 to 16, the one you can set: set sound volume to 10), listening, recording, recording seconds, last screenshot, last recording, profile names, message (what the bar under the picture says), recording presses, links allowed, event log and status json (all of it, with the TV's apps, as one JSON object). A script may ask for tv none to connect to no TV. A command waits until the TV has done it; one that cannot be done fails with the reason.

The standin tool, for Terminal and Xcode

Help, then Save the standin Command-Line Tool, saves a small tool wherever you choose (a folder on your PATH is handiest). It runs the commands above:

standin down 3
standin "open com.example.myapp; wait until still; select"
standin wait until text "Sign In" up to 30
standin expect field "cats"     # exits 1 unless it is so
standin --json "open Search; type cats"
standin screenshot              # prints the file's path
standin record start            # ... then: standin record stop
standin read                    # the screen's words
standin apps
standin status                  # everything, as JSON
standin log

It exits with 0 when every command was done, and with 1 and the reason when one was not, so it can stop a script, a test run or a build step. The first time, the macOS operating system asks whether Terminal (or the Xcode app) may control Stand-In TV; click OK.

Links

A link standintv://run?commands=down%202;%20select, or standintv://script/Smoke%20Test, does the same from anywhere a link can be opened: the Shortcuts app's Open URL, a launcher, a button on a control deck, a page of your own. Links control the TV only after you allow it, in Scripts, then Allow Links to Control the TV: otherwise any page could press your TV's buttons. The Shortcuts app also reaches everything through its Run AppleScript and Run Shell Script actions.

The log

Scripts, then Show Log, lists the newest 500 things done and seen: each command with how long it took, each event, each of your scripts run and what it wrote to its error output, each problem. A script reads it as event log, or standin log. Scripts, then Copy Log or Save Log, gives you this run's log to send with a question; it is kept only while Stand-In TV is open, and never holds what you type into the TV, only how many characters.

When something goes wrong

Whatever goes wrong, Stand-In TV says what happened under the picture or over it, with what to do and, where it can, a button that does it. The common ones:

No Apple TV device foundMake sure the TV is on, awake and on the same network as this Mac computer. Stand-In TV keeps looking.
Not allowed to look for devicesSystem Settings, Privacy & Security, Local Network: turn on Stand-In TV, then quit and reopen it.
The picture is not availableWake the TV. Make sure its sound is not going to a HomePod (on the TV: Settings, Video and Audio, Audio Output) and that it is paired with the Xcode app (Setting up the picture), then click Try Again.
No TV's picture comes, even one that worked before, or the macOS operating system says it could not connect to the TVRestart this Mac computer. The macOS operating system's own screen capture service, which brings the TV's picture to every app, can stop working until the Mac computer restarts. Never quit that service by hand (with killall): after that, no TV's picture comes until a restart.
The picture is being shown by another appOnly one app at a time can show it: close the QuickTime Player app's recording window, then click Try Again.
The TV is not sending a pictureIt is probably asleep: click Wake It.
The TV no longer recognizes this Mac computerIts pairing was removed on the TV (Settings, Remotes and Devices). Click Pair to pair again.
The TV already has as many remotes as it will takeOn the TV, Settings, Remotes and Devices, Remote App and Devices: remove one you no longer use, then click Pair.
Heard something that is not a commandHelp, then Voice Commands, lists what to say.
Your script went wrongScripts, then Show Log, says why. A script must be executable (in Terminal: chmod +x and its path), must be in the scripts folder, and must print only commands (anything else goes to its error output: print -u2 in zsh, echo ... >&2 in other shells).
A link asked to control the TVLinks may not until you allow them: Scripts, then Allow Links to Control the TV.
A wait ran outIt says what was so instead. Add up to and a number of seconds to wait longer, as wait until text "Welcome" up to 30.

Privacy

Stand-In TV collects nothing. The picture, the sound, your voice and everything you type go only between this Mac computer and your TV, on your own network. Screenshots and recordings are saved on this Mac computer. There are no accounts, no analytics and no advertising.

Scripts of your own are yours: Stand-In TV hands them only what the manual above says (an event's details, its state, and, for a voice script you put in place, what you said), and they go wherever your script sends them. That state includes what the TV's text field holds while its keyboard is up, as AppleScript's keyboard text and status json do, since a test must be able to check it; so a script of yours sees a password you type into the TV. Without a script of yours, nothing leaves. Record Presses as Commands never keeps what you type: it notes how many characters and leaves the quotes for you to fill.

Credits

The remote speaks the protocol the Apple TV device's own remote apps speak, as the open pyatv project by Pierre Ståhl and its contributors documents it, used under the MIT License (Stand-In TV, About Stand-In TV).

Questions and ideas: support@psk-intellect.com. PSK Intellect, LLC.