Work with cot command in CotEditor on Mac

CotEditor provides the cot command-line tool, which lets you open documents and receive text through standard input from the command line. To use the cot command, install it on your computer first.

Install the cot command

The cot command is bundled inside CotEditor at Contents/SharedSupport/bin/cot. You can install it anywhere in your PATH by creating a symbolic link in Terminal. If you don’t have a preferred location, placing the symbolic link in /usr/local/bin/ is recommended.

To create the symbolic link at the recommended location, run the following commands in Terminal:

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

Security authorization

macOS requires your permission when another app controls CotEditor through the cot command. Normally, authorization is requested the first time you run cot. If it isn’t, authorize it manually in System Settings > Privacy & Security > Privacy > Automation. Turn on CotEditor under your client app, such as Terminal. If you use the --wait option, you may also need to turn on System Events.

Install Python 3

The cot command is implemented in Python 3. Since macOS 12.3, Python is no longer included by default, so you need to provide a python3 command to use cot.

Installing Apple’s Command Line Developer Tools provides python3. Run the following command in Terminal to install the tools. You can also install python3 in any other way.

xcode-select --install

Uninstall the cot command

To uninstall the cot command from the recommended location, run the following command in Terminal:

unlink /usr/local/bin/cot

Use the command with options

The cot command supports the following options:

OptionDescription
-w, --wait

Wait for the opened document to be closed before returning to the prompt.

-r, --readonly

Open documents as read-only.

-n, --new

Create a new blank document. If you specify a file that does not exist, create it and open it.

-s, --syntax

Set a specific syntax for the opened document.

-l, --line <line>

Jump to a specific line in the opened document. <line> is an integer specifying the line.

-c, --column <column>

Jump to a specific column in the opened document. <column> is an integer specifying the column.

--goto <file[:line[:column]]>

Open FILE and move the insertion point to LINE and COLUMN (a syntactic sugar of the --line and --column options).

-g, --background

Open CotEditor without bringing it to the foreground.

-h, --help

Show help.

-v, --version

Print version information.

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

Execute the cot command

A simple cot command launches CotEditor, or activates it if CotEditor is already running.

cot

The following command opens the foo.txt file in CotEditor and moves the insertion point to line 200. If foo.txt doesn’t exist, the cot command returns an error.

cot --line 200 foo.txt

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

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

With the --goto option, you can specify where to move the insertion point using the shortened notation commonly found in compiler error messages. The following command opens the foo.txt file in CotEditor and moves the insertion point to line 200, column 4:

cot --goto foo.txt:200:4

Passing a dash (-) in place of a filename enters a mode to receive standard input. The text received is opened as a new document.

cot -

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

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

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

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

See also