我使用了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并不支持它们。
答案 0 :(得分: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