2017-08-05 56 views
2

我无法通过使用Applescript获取文本消息聊天的Id。获取邮件标识

这是到目前为止我的代码:

using terms from application "Messages" 

    on message sent theMessage for theChat 
     display dialog (get id of theChat) 
    end message sent 

end using terms from 

当我使用AppleScript的处理程序,我得到一个错误:

Can’t get id of «class ictt» id "iMessage;-;+1xxxxxxxxxx". (-1728) 

(X的代替电话号码)

我如何避免这个错误,并得到所需的输出只是iMessage;-;+1xxxxxxxxxx

回答

0

我不确定是什么触发了这个错误,但我找到了可靠的解决方法。我把这个语句放在一个try块中,并从错误信息中解析出id。

on splitText(sourceText, textDelimiter) 
    set AppleScript's text item delimiters to {textDelimiter} 
    set messageParts to (every text item in sourceText) as list 
    set AppleScript's text item delimiters to "" 
    return messageParts 
end splitText 

try 
    set myresult to get id of theChat 
on error errMsg 
    set errMsgParts to splitText(errMsg, "\"") 
    set errCount to count of errMsgParts 
    set myresult to item (errCount - 1) of errMsgParts 
end try 

这个工作原理是通过解析文本从引号中仅取出id。分割文本功能取自here