1

我正在使用 Craig Smith 的以下代码:

set chatsToKill to {}
tell application "Messages"
   set allChats to every chat
   repeat with eachChat in allChats
     set thePeeps to participants of eachChat
     repeat with oneParticipant in thePeeps
        if oneParticipant's handle contains "@" then
            if chatsToKill does not contain eachChat's id then set end of chatsToKill to eachChat's id
        end if
    end repeat
  end repeat
  repeat with deathChat in chatsToKill
        delete item 1 of (get every chat whose id = deathChat)
   end repeat
end tell

我想知道是否有一种方法可以删除用户句柄中只有 4 位数字的发件人的对话?

这 4 位数字总是不同的,也不相同。我尝试了各种通配符,但我发现 Applescript 不支持它们。

4

1 回答 1

0

此解决方案使用正则表达式。如果没有匹配,则抛出错误,该错误被忽略

set chatsToKill to {}
tell application "Messages"
    set allChats to every chat
    repeat with eachChat in allChats
        set thePeeps to participants of eachChat
        repeat with oneParticipant in thePeeps
            set theHandle to handle of oneParticipant
            try
                do shell script "echo " & quoted form of theHandle & " | egrep ^[0-9]{4}$"
                if chatsToKill does not contain eachChat's id then set end of chatsToKill to eachChat's id
            end try
        end repeat
    end repeat
    repeat with deathChat in chatsToKill
        delete item 1 of (get every chat whose id = deathChat)
    end repeat
end tell
于 2015-10-13T05:04:07.730 回答