CotEditorはAppleScriptおよびJXA (JavaScript for Automation)をサポートしています。
以下で説明するCotEditorのクラス・コマンド以外にも、AppleScriptで標準的に実装されている語句を使用することができます。CotEditorにおけるAppleScriptサポートの詳細な仕様については、辞書ライブラリを参照してください。ライブラリを参照するにはCotEditor上で次のようにします:
CotEditorで独自に定義されているクラス・プロパティです。
view opacitycontentstextlengthselectionencodingIANA charsetShift_JIS, EUC-JPなど)line endingCR / LF / CRLF)tab widthexpands tabwrap linescoloring styleline spacingcontentsrangeline rangelength省略可。また、lengthは0でも1でも、1行を選択する)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}
「selection」は単独では意味を持ちません。contentsなどのプロパティとともに使用してください。
locationが負の場合、対象ドキュメントの文字列の後ろから数えてlocation番目から始まる範囲となります。
lengthが正である場合、指定される範囲はlocationから数えてlength文字数分となります。また、対象ドキュメントの文字列の長さを超えてlengthが入力された場合、末尾までが範囲となります。
lengthが負である場合、指定される範囲は対象ドキュメントの文字列の後ろから数えてlength文字までとなります。もし、lengthの絶対値がlocationよりも小さい(locationよりも前に終了位置がある)場合には、locationが優先されlocation位置にキャレットが移動します({location, 0}が入力されたのと同じ)。
この指定方法はPHPのsubstrのそれにならっています。
選択位置を変える命令だけでは画面のスクロールは行われません。選択位置を見えるようにするためにはscroll to caretコマンドを使用してください。
CotEditorで独自に定義されているコマンドです。
([]で囲まれたものはオプションです)
write to consolewrite to console "Script failed."
findtrueを返す。見つからなければfalseを返す。for (Unicode text)RE (boolean)]wrap (boolean)]ignore case (boolean)]backwards (boolean)]検索は、現在の選択位置(キャレット位置)を基準に行われます。
例えば、wrapやbackwardsが指定されていなかったとき、選択位置以降に対象文字列がない場合にはfalseを返します。
RE(正規表現検索)の場合は、backwards(後方からの検索)ができません。同時に指定された場合はREが優先され、backwardsは無視されます。
find front document for "Apple" with ignore case
replace0を返す。for (Unicode text)to (Unicode text)all (boolean)]RE (boolean)]wrap (boolean)]ignore case (boolean)]backwards (boolean)]find同様、命令実行前の選択位置(キャレット位置)を基準に置換が行われます。書類全体を対象に実行するときはallを指定してください。
allオプションを付けて書類全体を対象に実行され置換が行われた場合、実行後の選択位置(キャレット位置)は書類の先頭になります。ただし、対象文字列が見つからなかった場合は選択位置(キャレット位置)は変更されません。
RE(正規表現検索)の場合は、backwards(後方からの検索)ができません。同時に指定された場合はREが優先され、backwardsは無視されます。
replace front document for "Apple" to "Orange" with all and ignore case
scroll to caretscroll to caret front document
convertto (Unicode text)lossy (boolean)convert front document to "Unicode (UTF-8)" without lossy
reinterpretas (Unicode text)ファイルそのものが未保存の場合は、falseを返します。
ファイル保存されていない変更部分は失われます。
reinterpret front document as "Japanese (EUC)"
shift leftshift rightshift right selection of front document
comment outuncomment現在のシンタックスにコメント記号が設定されていない、選択範囲にコメント記号がないなど、コマンドが実行できない場合はなにも行いません。
comment out selection of front document
stringin (list)無効な範囲を指定した場合などは、空の文字列を返します。
このコマンドは指定された選択範囲を変更しません。
string front document in {0, 10}
change caseto upper/lower/capitalized対象にできるのは`selection`オブジェクトだけです。
change case selection of front document to upper
change roman widthto half/full対象にできるのは`selection`オブジェクトだけです。
change roman width selection of front document to full
change kanato hiragana/katakana対象にできるのは`selection`オブジェクトだけです。
change kana selection of front document to katakana
smarten quotesstraighten quotes対象にできるのは`selection`オブジェクトだけです。
smarten quotes selection of front document
smarten dashes対象にできるのは`selection`オブジェクトだけです。
smarten dashes selection of front document
normalize unicodeto NFKC/NFD/NFC/NFKD/NFKC Casefold/Modified NFC/Modified NFD対象にできるのは`selection`オブジェクトだけです。
normalize unicode selection of front document to NFC
move line upmove line down対象にできるのは`selection`オブジェクトだけです。
sort linesreverse lines対象にできるのは`selection`オブジェクトだけです。
delete duplicate line対象にできるのは`selection`オブジェクトだけです