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