0

一段时间以来,我一直在使用 BBEdit 进行开发。我经常使用 BBEdit 进行查找和替换。有时,我想从选定的文本中删除所有行尾和制表符,我很容易在 BBEdit 中使用正则表达式查找,因为它的查找和替换是可编写脚本的。Coda 有能力执行 grep 查找和替换,但我不认为它是可编写脚本的。所以,我从两种方式来解决这个问题:1)看看我是否可以用 Applescript 在 Coda 中进行 grep 查找和替换(我认为这是不可能的),或者 2)将我的文本传递到命令行并执行它那样。除非有人有前者的例子,否则这个问题将与通过命令行进行相关。

我正在使用 Coda 的一个内置脚本作为模板,并结合其他一些关于此问题的类似线程。我不是 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
4

1 回答 1

1

试试这个:

set shellscriptString to "echo " & quoted form of someText & "|tr -d '\\\t\\r\\n\\x'" as string
于 2011-05-25T21:02:58.907 回答