# Server.setHook(_:to:at:in:)

- **Module:** Server
- **Package:** libtmux-swift
- **Language:** Swift
- **Kind:** method
- **Source:** https://github.com/libtmux/libtmux-swift/blob/f02a4668570e1cc5198c941413750e021f42c214/Sources/LibTmux/Options.swift#L222
- **Page:** https://libtmux.org/reference/swift/server-sethook(_-to-at-in-)/

```
Server.setHook(_:to:at:in:)(name: String, to: String, at: Int?, in: HookScope) -> TmuxReply
```

Binds a command to a hook.

Without an index this replaces every command bound to the name, leaving
the one given at slot 0 — tmux assigns the array, not just an element.
Pass `at:` to write one slot and leave its neighbours alone.

A name tmux does not know is a reply reporting why, not a thrown error.

- Parameters:
  - name: a hook name tmux knows, such as `after-new-window`.
  - command: the tmux command line to run, unparsed until tmux runs it.
  - index: which slot to write, or every slot when omitted.
  - scope: which table to write to.

## Raises

- `TmuxError`
