【问题标题】:Applescript -- osx mail -- make some words bold if a paragraph starts with a 3 digit numberApplescript -- osx mail -- 如果段落以 3 位数字开头,则将某些单词加粗
【发布时间】:2021-01-03 14:09:29
【问题描述】:

我有一个自动生成电子邮件的applescript。以前,脚本会查找以“Ep”开头的任何段落,并将该段落的前两个单词加粗。

但是现在,电子邮件正文发生了变化。我们正在从电子邮件正文中删除“Ep”部分,因此我想将任何以 三位数 开头的段落的前两个单词加粗。我四处搜索,但我不知道如何让 applescript 查找以任意三位数开头的 段落

以前的代码(基本上)是:

tell application "Mail"
    activate
    
    set emailSubject to (" Daily Reports") as rich text
    set emailContent to ("Ep123 - XYZ: This is just an example
    This line shouldn't be bold
    
Ep980 - ABC: This is a second example")
    
    set theMessage to make new outgoing message with properties {visible:true, subject:emailSubject, content:emailContent}
    
    tell theMessage
        set font of (words 1 thru 2 of (every paragraph where the first word starts with "Ep")) to "Helvetica Bold"
        
        make new to recipient at end of to recipients with properties {address:"test@example.com"}
    end tell
end tell

我们将不胜感激。

【问题讨论】:

    标签: macos email formatting applescript


    【解决方案1】:

    像这样修改脚本:

    tell application "Mail"
        activate
        
        set emailSubject to (" Daily Reports") as rich text
        set emailContent to ("123 some text 
    724: some text
    some random text
    645Fgz: and more text")
        
        set theMessage to make new outgoing message with properties {visible:true, subject:emailSubject, content:emailContent}
        
        tell theMessage
            repeat with a_paragraph in paragraphs
                set lead_in to (characters 1 through 4 of a_paragraph) as rich text
                ignoring punctuation and hyphens
                    considering numeric strings
                        if lead_in > 99 and lead_in < 1000 then
                            set font of (words 1 thru 2 of a_paragraph) to "Helvetica Bold"
                        end if
                    end considering
                end ignoring
            end repeat
            make new to recipient at end of to recipients with properties {address:"test@example.com"}
        end tell
    end tell
    

    当前三个字符是数字并且第四个字符是字母、空格或标点符号时,这会更改段落中前两个单词的字体。它不会捕获以 0 开头的数字(例如 050)。

    请注意,如果您使用暗模式,此脚本还会出于某种原因更改字体颜色。你可能需要解决这个问题。

    【讨论】:

    • 谢谢!经过一些测试(和目标后移动),我注意到连续两个换行符会导致索引错误。我最终在“set lead_in”行周围添加了 try / end try。完美运行。
    猜你喜欢
    • 2017-06-12
    • 2013-03-09
    • 2011-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-21
    • 1970-01-01
    相关资源
    最近更新 更多