# Enroll a Mac

> Enroll a Mac with Xcode so Rehearsal knows it and the simulators it lists.

Source: https://rehearsal.dev/docs/cli/enrolled-macs

Enrolling a Mac is separate from connecting a web app. [Connect a local app](https://rehearsal.dev/docs/cli/connect-a-local-app.md) lets Rehearsal's browsers reach a website on your computer. An enrolled Mac tells Rehearsal that it is online and which simulators it has.

## What works today

- Enroll a Mac and keep it online with `rehearsal host join`.
- See which Macs are online, whether each one is free or in use, and the simulators it lists.
- Retire a Mac to end its access to Rehearsal.

## Not yet

- Rehearsal does not run tests or explorations on an enrolled Mac yet.
- A Mac does not report the app builds it has.

## Before you start

- The CLI is [installed](https://rehearsal.dev/docs/cli/install.md) on the Mac.
- Xcode is installed, for the simulators. A Mac without Xcode can join and lists none.
- Enrolling and retiring need the `hosts` scope and **Manage projects**. Listing Macs needs `testing:read` and **View projects**.

`rehearsal login` does not ask for `hosts`. A new sign-in replaces the old one, so name `hosts` beside the scopes you already use:

```sh
rehearsal login --scope tunnel --scope testing:read --scope testing:run --scope hosts
```

## Enroll a Mac

1. **Ask for a code**

   ```sh
   rehearsal hosts enroll --name "Office Mac" --workspace <workspace-id>
   ```

   This prints a code and the command to run on the Mac. The code works for fifteen minutes.

2. **Join on the Mac**

   ```sh
   rehearsal host join --api https://api.rehearsal.dev -- <code>
   ```

   The code comes after `--`. Keep the command running: it reports the Mac every thirty seconds.

3. **Check that it is online**

   ```sh
   rehearsal hosts list --workspace <workspace-id> --json
   ```

## Keep it online

Press `Ctrl+C` to stop `rehearsal host join`. Rehearsal shows the Mac offline within three minutes. Run `rehearsal host join` without a code to resume.

The Mac keeps its own credential in `~/.config/rehearsal/host.json`, apart from your sign-in. `rehearsal login` and `rehearsal logout` leave it alone.

## Simulators

The Mac lists up to twenty available simulators, each name once on its newest runtime. Newer runtimes come first.

## Retire a Mac

```sh
# Anywhere you are signed in
rehearsal hosts retire "Office Mac" --workspace <workspace-id>
# Then on the Mac, after stopping host join
rehearsal host forget --yes
```

Retiring is permanent. To join the same Mac again, give it a new name and ask for a new code.

## Next steps

- Read the [Command reference](https://rehearsal.dev/docs/cli/commands.md) for every flag.
- [Connect a local app](https://rehearsal.dev/docs/cli/connect-a-local-app.md) to test a website on your computer.
