使用Applescript删除尾声(或其他应用程序)中的行尾

使用Applescript删除尾声(或其他应用程序)中的行尾,applescript,coda,Applescript,Coda,我已经结合使用BBEdit进行开发一段时间了。我经常使用BBEdit查找和替换它。有时,我想从文本选择中删除所有行尾和制表符,我在BBEdit中使用regex find很容易做到这一点,因为它的find和replace是可以编写脚本的。Coda能够执行grep查找和替换,但我认为它不可编写脚本。因此,我从两个方面着手:1)看看我是否可以用Applescript(我认为这是不可能的)在尾码中进行grep查找和替换,或者2)将我的文本传递到命令行并以这种方式执行。除非有人有前一个例子,否则这个问题将

我已经结合使用BBEdit进行开发一段时间了。我经常使用BBEdit查找和替换它。有时,我想从文本选择中删除所有行尾和制表符,我在BBEdit中使用regex find很容易做到这一点,因为它的find和replace是可以编写脚本的。Coda能够执行grep查找和替换,但我认为它不可编写脚本。因此,我从两个方面着手:1)看看我是否可以用Applescript(我认为这是不可能的)在尾码中进行grep查找和替换,或者2)将我的文本传递到命令行并以这种方式执行。除非有人有前一个例子,否则这个问题将与通过命令行执行有关

我使用Coda的一个内置脚本作为模板,并结合其他一些类似的线程来讨论这个问题。我不是Applescript或regex专家,所以如果这是一个简单的错误,请对我宽容一些

我输入的文本可能变化很大,但它通常是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
试试这个:

set shellscriptString to "echo " & quoted form of someText & "|tr -d '\\\t\\r\\n\\x'" as string