CotEditor provides the cot command-line tool, which lets you open documents, receive text through standard input, and control CotEditor directly from the command line. To use the cot command, install it on your computer first.
cot commandYou can install the cot command-line tool by creating a symbolic link in Terminal. The actual executable is built in CotEditor at Contents/SharedSupport/bin/cot. 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 /usr/local/bin/
ln -s /Applications/CotEditor.app/Contents/SharedSupport/bin/cot /usr/local/bin/cot
macOS requires user authorization when an external app invokes CotEditor through the cot command. Normally, authorization is requested the first time you run the cot command. In some cases, however, you may need to authorize it manually in System Settings > Privacy & Security > Automation. Turn on CotEditor under your client app, such as Terminal. For the --wait option, you may also need to turn on System Events.
The cot command is implemented in Python 3. Since macOS 12.3, Python is no longer bundled with macOS, so you need to install python3 manually for the cot command.
Installing Apple’s Command Line Developer Tools provides python3. Run the following command in Terminal to install the tools. You can also install python3 using any other method.
xcode-select --install
cot commandTo uninstall the cot command from the recommended location, run the following command in Terminal:
unlink /usr/local/bin/cot
The cot command supports the following options:
| Option | Description |
|---|---|
-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. |
-s, --syntax |
Set a specific syntax for the opened document. |
-l, --line <line> |
Jump to a specific line in the opened document. |
-c, --column <column> |
Jump to a specific column in the opened document. |
--goto <file[:line[:column]]> |
Open |
-b, --background |
Do not bring the app 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).
cot commandA 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. The cot command does nothing if foo.txt doesn’t exist.
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"