將 RTF 檔案中某些字串的所有實例設為粗體

將 RTF 檔案中某些字串的所有實例設為粗體

假設我有一個包含以下內容的 RTF 檔案:

我喜歡狗。大多數人都喜歡狗。有些貓喜歡狗。

現在,我想將「狗」的每個實例都加粗。如何以最簡單的方式實現這一目標,而無需手動進行所有更改?

答案1

最簡單的方法是在文字模式(不是 rtf)下開啟文檔,然後進行搜尋並用這些參數替換:

  • 搜尋:dog
  • 用。\b dog \b0

保存您的文件而不修改任何其他內容,應該沒問題。不過,您應該事先複印一份原件,以防出現問題。

答案2

您也可以在 TextEdit 中開啟 RTF 文件,然後在 AppleScript 編輯器中執行以下腳本:

set x to "dogs"
set text item delimiters to x
tell application "TextEdit" to tell document 1
    set ti to text items of (get its text)
    repeat with i from 1 to (count of ti) - 1
        set l to count of (items 1 thru i of ti as text)
        set font of characters l thru (s + (length of x)) to "Helvetica Bold"
    end repeat
end tell

相關內容