Applescript 正在获取Chat消息的Id
我无法通过使用Applescripts获取短信聊天的Id 以下是我目前的代码:Applescript 正在获取Chat消息的Id,applescript,Applescript,我无法通过使用Applescripts获取短信聊天的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 i
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代替电话号码)
如何避免此错误并获得所需的just
iMessage;-+1XXXXXXXXX
?我不确定是什么触发了此错误,但我找到了一个可靠的解决方法。我将语句放在一个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。拆分文本函数取自