A collection of scripts for CotEditor providing formatting, linting, and editing utilities accessible from the Script menu, along with an installer to deploy them.
These scripts are primarily useful for editing code rather than plain text. Anyone comfortable with the command line should find them straightforward to install, customize, and extend.
Open Help → CotEditor Help and look under Script CotEditor, particularly:
- Customize the Script menu — naming conventions, keyboard shortcuts, and menu separators
- Automate tasks using UNIX scripts — how CotEditor passes document content to scripts and reads back results
src/ Template scripts with @@tool@@ placeholders (tracked in git)
Scripts/ Generated by installScripts — real tool paths (gitignored)
installScripts Detects tool paths and builds Scripts/ from src/
README.md
The installer routes files automatically based on filename:
- Numbered files (starting with a digit) are installed directly into the CotEditor Application Scripts directory and appear in the Script menu
- Non-numbered files are installed into the
_lib/subdirectory and are hidden from the menu — these are helper scripts called by the numbered scripts
You can remove, add, or renumber the numbered scripts to suit your needs by
editing files in src/ and re-running installScripts.
The scripts are organized into sections separated by menu dividers.
You can renumber them to change the order or move scripts between
sections. Leading numbers, keyboard shortcuts, and .sh are stripped
from the filename in the Scripts menu.
Formatting and linting
05)Format.@~F.sh Format document using syntax-appropriate tool
10)LineWrap.@~L.sh Wrap lines at 70 characters
15)shellcheck.sh Lint shell scripts with shellcheck
20)- Menu separator
Markdown file editing
25)singleTicks.sh Wrap selection in single backticks
30)tripleTicks.sh Wrap selection in triple backticks
35)- Menu separator
Pasting code into an AI chat
40)copyWithXML.sh Copy selection wrapped in an XML tag, e.g. <bash>...</bash>
Cleaning up AI chat exports
45)convertXML.sh Convert XML tag blocks to fenced code blocks
50)removeToolUsage.sh Remove tool-use noise from AI chat exports
55)- Menu separator
Debugging
60)printenv.sh Print environment variables (useful when debugging PATH issues)
Helper scripts (installed into _lib/, hidden from menu)
prettier.sh Format with prettier (CSS, HTML, JSON, Markdown, YAML)
prettier-eslint.sh Format JavaScript with eslint then prettier
prettier-awk.sh Format AWK files with prettier-plugin-awk
fmt-wrap_70.sh Wrap lines at 70 characters
prettier-wrap_70.sh Wrap long lines with prettier --prose-wrap always
gofmt.sh Format Go files
ruff.sh Format Python files
rustfmt.sh Format Rust files
shfmt.sh Format shell scripts
swiftformat.sh Format Swift files
remove_tools.awk Remove AI tool-use blocks and collapse excess blank lines
See the scripts themselves for details on their purpose and requirements.
The helper scripts delegate to external CLI tools. Install whichever tools correspond to the languages you work with:
| Tool | Language(s) |
|---|---|
| prettier | CSS, HTML, JavaScript, JSON, Markdown, YAML |
| prettier-plugin-awk | AWK (optional, requires prettier) |
| eslint | JavaScript |
| gofmt | Go |
| ruff | Python |
| rustfmt | Rust |
| sd | required by 45)convertXML.sh |
| shfmt | Shell |
| swiftformat | Swift |
| shellcheck | Shell (linting) |
You do not need all of them — 05)Format.@~F.sh detects the file type and
calls only the relevant tool. Helper scripts whose required tools aren't
installed will be skipped automatically by the installer.
./installScriptsRun with --dry-run first to preview what will happen:
-h, --help Show help and exit
-d, --dry-run Preview what would be copied without making changes
-v, --verbose Show all actions including skipped files
The installer:
- Detects tool locations using
command -vand prints a summary showing where each tool was found (or reporting it as missing) - Generates
Scripts/fromsrc/by substituting@@tool@@tokens with the detected paths. Helper scripts whose required tools aren't installed are skipped with a clear message - Copies the generated scripts into the CotEditor Application Scripts directory, updating only files whose content has changed
Because CotEditor launched by clicking a file inherits only a minimal PATH
(/usr/bin:/bin:/usr/sbin:/sbin), substituting real tool paths into the
scripts at install time is what makes them reliably work regardless of how
you manage your tools (Homebrew, Volta, MacPorts, Cargo, system installers,
etc.).
If you later install a new tool or move an existing one, just re-run
./installScripts and the paths will be refreshed.
Edit files directly in src/ — installScripts regenerates Scripts/ from
src/ on each run, so any changes in Scripts/ alone will be lost. The
installer routes files automatically:
- Give a file a numeric prefix like
75)myScript.shto make it a menu entry - Name it without a leading digit (e.g.
myHelper.sh) to make it a hidden helper in_lib/
If your new helper relies on a CLI tool, wrap the invocation with a token:
"@@toolname@@" --some-flag "$1"then add toolname to the KNOWN_TOOLS array near the top of installScripts.
JavaScript formatting requires eslint with a configuration file and its
dependencies. The simplest setup is to clone this repo into ~/Projects
and run npm install there:
cd ~/Projects/CotEditorScripts # or wherever you cloned the repo
npm installprettier-eslint.sh searches ~/Projects automatically (two levels deep) for
an eslint.config.mjs and uses the first one it finds. If you have multiple
eslint configs and want to use a specific one, set ESLINT_CONFIG in your
shell profile:
export ESLINT_CONFIG="$HOME/Projects/myproject/eslint.config.mjs"