0
我一直在使用BBEdit來開發一段時間。我經常使用BBEdit來查找和替換。有時候,我想從文本中刪除所有行結束符和製表符,我很容易用BBEdit中的正則表達式查找,因爲它的查找和替換是可編寫的。 Coda有能力執行grep查找和替換,但我不認爲它是腳本化的。所以,我已經從兩個方面來處理這個問題:1)看看我能否用AppleScript(我認爲是不可能的)在Coda中進行grep查找和替換,或者2)將我的文本傳遞到命令行並執行它那樣。除非有人有前者的例子,否則這個問題將通過命令行來完成。使用AppleScript刪除Coda(或其他應用程序)中的行結尾
我正在使用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
這工作!謝謝! – 2011-05-25 21:29:02