しばらくの間、BBEdit を併用して開発を行ってきました。検索と置換には BBEdit を頻繁に使用します。ときどき、選択したテキストからすべての行末とタブを削除したいことがあります。これは、検索と置換がスクリプト化可能であるため、BBEdit の正規表現検索で簡単に実行できます。Coda には grep の検索と置換を実行する機能がありますが、スクリプト可能ではないと思います。したがって、私はこれに 2 つの方法でアプローチしました: 1) Applescript を使用して Coda で grep find and replace を実行できるかどうかを確認する (これは可能ではないと思います)、または 2) テキストをコマンド ラインに渡して実行します。その方法。誰かが前者の例を持っていない限り、この質問はコマンドライン経由で行うことに関連しています。
この問題に関する他の同様のスレッドと組み合わせて、Coda の組み込みスクリプトの 1 つをテンプレートとして使用しています。私は Applescript や正規表現の専門家ではないので、これが単純な間違いである場合は、ご容赦ください。
入力するテキストは大きく異なる可能性がありますが、通常は HTML および/または JS コードです。
このスクリプトは実行されますが、何も起こりません。何か案は?
-- script settings
on CodaScriptSettings()
return {displayName:"Remove Line Endings", inContextMenu:"yes"}
end CodaScriptSettings
-- actual script
tell application "Coda"
try
tell current split of front document
if selected text is not equal to "" then
set someText to selected text
else
set someText to contents
end if
end tell
on error
beep
return
end try
end tell
set shellscriptString to "echo " & quoted form of someText & "|sed \"s/[\\t\\r\\n\\x]+/ /g\"" as string
set shellresult to do shell script shellscriptString without altering line endings
tell application "Coda"
try
tell current split of document 1
if selected text is not equal to "" then
set selected text to shellresult
else
set contents to shellresult
end if
end tell
on error
beep
end try
end tell