Applescript :(不能将[...]的第2段变成Unicode文本类型。)

时间:2014-02-21 06:04:07

标签: applescript

tell application "Mail"
        set emailSelection to (get selection)
    set theText to content of (item 1 of the emailSelection)
    set subText to paragraph 1 of theText
end tell

我收到错误说:

  

无法制作第2段“下面是您的反馈表的结果。它是由”提交到Unicode文本类型。

注意第1段第2段的差异。


修改

还尝试将消息内容的内容复制到新对象(未引用)以删除任何特定于对象的怪异。但错误消息仍然引用回邮件消息而不是新对象,我认为这是错误的。

try
tell application "Mail"

    set emailSelection to (get selection)
    set theMessage to (item 1 of the emailSelection)
    log "1 ****** " & return & content of theMessage

    copy contents of (item 1 of the emailSelection) to theText
    log " 2 ****** " & return & content of theText

    set subText to (the first paragraph of theText)
    log " 3 ****** " & return & content of theText

    --  set subText to paragraph 1 of theText as Unicode text

end tell

on error the error_message number the error_number
    display dialog "Error: " & the error_number & ". " & the error_message buttons {"OK"} default button 1
end try

错误消息:

  

错误:-1728。邮件收到错误:无法获取帐户“IMAP PL ...”邮箱“INBOX”的邮件ID 740166的第1段。

1 个答案:

答案 0 :(得分:1)

您的脚本似乎可以在我的机器上运行(OS X 10.9.1)。

可能有助于诊断(try-block在出现故障时吐出错误消息):

tell application "Mail"
    try
        set emailSelection to (get selection)
        set theText to content of (item 1 of the emailSelection)
        set subText to paragraph 1 of theText
    on error the error_message number the error_number
        display dialog "Error: " & the error_number & ". " & the error_message buttons {"OK"} default button 1
    end try

end tell

我使用新创建的消息以及一些收到的消息对其进行了测试。可能是这里不起作用的消息格式。因为这个想法可能有助于做这样的事情吗?

set subText to (paragraph 1 of theText) as Unicode text