2
votes

I'm trying to check if phone not from my contact list is registered in the iMessage.

There is two general approaches that I've tryed.

  1. Send message to phone number if it's in buddy list
    
    on run argv
        set toAddress to "+380631111111"
        set message to "Test"
        tell application "Messages"
            set targetService to 1st service whose service type = iMessage
            set targetBuddy to buddy toAddress of targetService
            delay 1
            if targetBuddy exists then
                send message to targetBuddy
            end if
            #delay 5
        end tell
    end run
    

Why it doesn't work? Even tho it can send messages by removing "delay 1" I don't want to spam users. With delay it can only check if phone in my buddy (contact) list.

  1. Trying to get button color by UI Automation. (Button goes red when phone is not registered in iMessage, and blue otherwise.)


tell application "System Events" to tell process "Messages"
    set input to "TEST" as text
    click button 1 of group 1 of splitter group 1 of window 1
    delay 1
    keystroke "+380931111111"
    keystroke return
    delay 1
    set phoneInput to text field 1 of scroll area 2 of splitter group 1 of window 1
    set phoneInputElement to menu button 1 of phoneInput
    #set phoneInputElementColor to color of phoneInputElement
end tell

I'm unable to get button color because it doesn't have such property. Also I tried to get data from context menu where application says "+38093111111 is not registered in iMessage" but I can't reach context menu from AppleScript.

Please, help me to accomplish my mission :)

1
I would like to help you accomplish your mission. Let me start by asking about two things you wrote: * I'm trying to check if phone not from my contact list is registered in the iMessage.* and * Send message to phone number if it's in buddy list* These seem like two different problems or issues. Could you be more specific about what you'd like to do? I think it may be possible without resorting to GUI scripting; the Messages dictionary is pretty extensive. So, for now, I'm going to not bother with the 2nd approach. - CRGreen
@CRGreen nice to hear that someone willing to help :). Main issue is to check whatever phone is registered in iMessage or not. If this is not possible at least to check text message delivery status (so we can send test messages to check is iMessage activated). - Andrew Dryga
It may be necessary to involve the Contacts app for this, since additions (like phone numbers) to buddies are automatically added to the contacts, but not to any scriptable property of a buddy. At least this is what I've determined so far (I guess "pretty extensive" is not quite right) - CRGreen
Are you trying to determine if the person from your contact list is also using an iPhone, or is this something different? I wrote a script a few years back that could go through a contact list and pick out which users were using iPhones, and then add them into a new 'iPhone' contacts group. - l'L'l
Did you get your answer to this question? I have the same issue. I want to know if a number is registered in iMessage or not? @AndrewDryga - Mohammad Zarei

1 Answers

-1
votes

You could get the color of the button moving the mouse pointer on it and then scripting the application Digital Color Meter. First calculate the x and y position of the button based on some gui element on the iMessage window, using the position and size attributes.
Then move the pointer to the calculated position:

do shell script "/usr/bin/python -c \"import objc;bndl = objc.loadBundle('CoreGraphics', globals(), '/System/Library/Frameworks/ApplicationServices.framework');objc.loadBundleFunctions(bndl, globals(), [('CGWarpMouseCursorPosition', 'v{CGPoint=dd}')]);CGWarpMouseCursorPosition((" & x & "," & y & "));\""

Use Digital Color Meter to get the color of the pixel pointed, in rgb format:

tell application "Digital Color Meter" to activate
tell application "System Events"
    tell process "Digital Color Meter"
        click menu item 1 of menu 1 of menu bar item 4 of menu bar 1
        delay 1
    end tell
    set rgbColors to words of (the clipboard)
end tell