【问题标题】:Remove Line Endings in Coda (or other apps) with Applescript使用 Applescript 删除 Coda(或其他应用程序)中的行尾
【发布时间】:2011-05-26 05:02:58
【问题描述】:

我一直在使用 BBEdit 进行开发。我经常使用 BBEdit 进行查找和替换。有时,我想从选定的文本中删除所有行尾和制表符,我很容易在 BBEdit 中使用正则表达式查找,因为它的查找和替换是可编写脚本的。 Coda 有能力执行 grep 查找和替换,但我不认为它是可编写脚本的。所以,我从两种方式来解决这个问题:1)看看我是否可以在 Coda 中用 Applescript 进行 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

【问题讨论】:

    标签: applescript coda


    【解决方案1】:

    试试这个:

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

    【讨论】:

      猜你喜欢
      • 2018-11-15
      • 2011-09-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-30
      • 1970-01-01
      • 1970-01-01
      • 2013-06-23
      相关资源
      最近更新 更多