PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Tuesday, July 12, 2022

[FIXED] How to use Applescript to delete Conversations whose senders contain email addresses from the Messages app

 July 12, 2022     applescript, messages     No comments   

Issue

I want to use applescript to delete conversations from people who sent me messages using email addresses. I want to keep all conversations from mobile numbers, but delete all conversations, in which my correspondent is an email address.

I've tried:

tell application "Messages"
    tell every item
        delete (every item whose sender contains ".com")
    end tell
    save
end tell

Solution

All scriptable applications have an AppleScript Dictionary that can be accessed from Script Editor via the Window --> Library menu. Reading through an application's dictionary can help you obtain the proper terms for generating a script to do your bidding.

The script below will successfully create a list of chat IDs of all chats (conversations) wherein at least one participant is using an email address. I have not tested the delete section, since I am not interested in deleting anything. I strongly recommend that you run Time Machine or another backup service BEFORE executing that portion of the script, just in case you get unexpected results.

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


Answered By - Craig Smith
Answer Checked By - Marilyn (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing