# Work with `cot` command in CotEditor on Mac

CotEditor has 'cot' command-line tool which allows you to control CotEditor from the command-line. To use `cot` command, install it at first.

## Install cot command

You can install the `cot` command-line tool to the desired location by creating a symbolic link in Terminal. The `cot` substance is bundled at '`Contents/SharedSupport/bin/cot`' in CotEditor.app. Unless you are particular about the location, we recommend creating the symbolic link at '`/usr/local/bin/`'.

To create a symbolic link at the recommended location, run the following lines in Terminal.

    mkdir /usr/local/bin/
    ln -s /Applications/CotEditor.app/Contents/SharedSupport/bin/cot /usr/local/bin/cot

### Security authorization

In macOS, user authorization is required to control CotEditor from other applications in which `cot` command is used. The authorization is normally done by the dialog that appears when using the `cot` command for the first time. However, in some cases, you may need to authorize it manually from System Settings > Privacy & Security > Automation. Select the checkbox for CotEditor (and also System Events for `--wait` option) under your client application, such as Terminal.

### Installation of Python 3

The cot command is implemented in Python 3. However, because Python has no longer been bundled into the system since macOS 12.3, you need to install `python3` manually for the cot command.

The developer tools provided by Apple include `python3`. Run the following line in Terminal to install Apple’s Command Line Developer Tools. Obviously, any `python3` installed by other methods can be used as well.

    xcode-select --install

## Uninstall cot command

To uninstall `cot` command at the recommended location above in Terminal is like the following:

    unlink /usr/local/bin/cot

## Use with options

The following options can be used on `cot` command.

Option | Description
--- | ---
`-w`, `--wait` | Wait for opened file to be closed before returning to a prompt.
`-n`, `--new` | Create a new blank document.
`-s`, `--syntax` | Set specific syntax to opened document.
`-l`, `--line` `<line>` | Jump to specific line in opened document. `<line>` is an integer specifying the number of line.
`-c`, `--column` `<column>` | Jump to specific column in opened document. `<column>` is an integer specifying the number of column.
`-b`, `--background` | Do not bring the application to the foreground.
`-h`, `--help` | Show help.
`-v`, `--version` | Print version information.

For `--line` and `--column` options, you can specify a negative number to count from the end of the document (`--line` option) or a line (`--column` option).

## Examples

A simple `cot` command launches CotEditor, or just activate it if CotEditor is already running.

    cot

The following command opens the foo.txt file on CotEditor and moves the insertion point to line 200 in the opened document. `cot` command does nothing if foo.txt file does not exist.

    cot --line 200 foo.txt

The following command opens the foo.txt file on CotEditor and moves the insertion point to the end of the document.

    cot --line -1 --column -1 foo.txt

You can also pipe a text. Then, CotEditor opens a new document with the piped text.

    echo "I am a dog but also a cow at the same time." | cot

Using `--wait` option, CotEditor can be used as the editor for `git`.

    git config --global core.editor "cot -w"

## See also

- Change General settings