CotEditor supports AppleScript and JXA (JavaScript for Automation).
It has own AppleScript dictionary so that you can look up all the classes or commands available with CotEditor. To open the dictionary:
The original classes and properties that are defined in CotEditor.
view opacity
contents
text
length
selection
encoding
IANA charset
Shift_JIS
, EUC-JP
)line ending
CR
/ LF
/ CRLF
)tab width
expands tab
wrap lines
coloring style
line spacing
contents
range
line range
length
can be omitted, one line will be selected even if it were 0
or 0
)selection
contents of selection of document 1
set contents of selection of front document to "Apple"
range of selection of front document
set range of selection of front document to {1, 12}
set line range of selection of front document to 10
set range of selection of front document to {-15, -1}
The selection
property doesn't work by itself. Use this property with others such as contents
.
When ‘location’ is a negative value, the selection range starts from the ‘location’-th last character.
When ‘length’ is a positive value, the selection range becomes the ‘length’ characters starting from ‘location.’ If ‘length’ is larger than the number of the rest characters in the document, the range will be from ‘location’ to the end.
When ‘length’ is a negative value, the selection range ends at the ‘length’-th last character. If the absolute value of ‘length’ is smaller than ‘location’ (i.e. the selection's end point is before ‘location’), the caret just moves to ‘location’ (same as when {location, 0} was input).
This specifying method is modelled after that of PHP's substr
.
The command for changing selection doesn't scroll the window. Use the scroll to caret
command to make the selection remain in the view.
The original commands that are defined in CotEditor.
(properties surrounded by [ ] are options)
write to console
write to console "Script failed."
find
true
, if any, otherwise returns false
.for
(Unicode text)RE
(boolean)]wrap
(boolean)]ignore case
(boolean)]backwards
(boolean)]The search starts from the current selection (caret position).
For example, when not using the wrap
or backwards
options and when there are no matching string after the current selection, then false
is returned.
The regular expression search cannot search backwards. If both options were specified at the same time, RE
takes precedence and backwards
is ignored.
find front document for "Apple" with ignore case
replace
0
.for
(Unicode text)to
(Unicode text)all
(boolean)]RE
(boolean)]wrap
(boolean)]ignore case
(boolean)]backwards
(boolean)]As in the case of the find
command, the search starts from the current selection (caret position). Use the all
option for searching the whole document.
After replacing the whole document using the all
option, the caret moves to the head of the document. If there were no matching string, the caret doesn't move.
The regular expression search cannot search backwards. If both options were specified at the same time, the backwards
option is ignored.
replace front document for "Apple" to "Orange" with all and ignore case
scroll to caret
scroll to caret front document
convert
to
(Unicode text)lossy
(boolean)convert front document to "Unicode (UTF-8)" without lossy
reinterpret
as
(Unicode text)Returns false
if the file has never been saved.
Changes that are not yet saved will be lost.
reinterpret front document as "Japanese (EUC)"
shift left
shift right
shift right selection of front document
comment out
uncomment
These commands do nothing if not possible for example in cases where no delimiters are set in the current syntax style or no comment delimiters to remove are available.
comment out selection of front document
string
in
(list)Returns an empty string if the specified range was invalid.
This command does not change the specified range.
string front document in {0, 10}
change case
to
upper
/lower
/capitalized
Works only for ‘selection’ objects.
change case selection of front document to upper
change roman width
to
half
/full
Works only for ‘selection’ objects.
change roman width selection of front document to full
change kana
to
hiragana
/katakana
Works only for ‘selection’ objects.
change kana selection of front document to katakana
normalize unicode
to
NFKC
/NFD
/NFC
/NFKD
/NFKC Casefold
/Modified NFC
/Modified NFD
Works only for ‘selection’ objects.
normalize unicode selection of front document to NFC
move line up
move line down
Works only for ‘selection’ objects.
sort lines
reverse lines
Works only for ‘selection’ objects.
delete duplicate line
Works only for ‘selection’ objects.