1

I'm trying to do a number checker in imessage. We all know that there is no such api, so I'm trying to use the tools at hand. The main took with past issues on this site on this topic.

I made a loop that inserts a number into a string, and by the color of the number (blue - registered, red - missing), using the standard utility Digital Colors Meter determines the color of the number. Then, depending on the color, it either adds a variable with a number from the initial txt file to the new one, or starts the script from the beginning. At least it should be.

But something is going wrong. It checks the color, inserts numbers, everything is fine, but apparently the wrong condition, apparently the wrong data types. It inserts different numbers into the scatter. Some will insert, some will not, regardless of the initial condition. What could be the reason? Where is the error? And is it possible to make it so that after a certain number of verified numbers, he himself deleted open dialogs with these numbers?

repeat with n in client
    activate application "Messages"
    repeat
        tell application "System Events" to tell process "Messages"
            key code 45 using command down
            keystroke n
            delay 1
            key code 36
            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
                end tell
                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((" & 1002 & "," & 222 & "));\""
                set rgbColors to words of (the clipboard)
            end tell
            if rgbColors is equal to {"77", "39", "38"} then
                exit repeat
            else
                do shell script "echo " & quoted form of n & " >> /Users/oneone/Desktop/base2.txt"
            end if
        end tell
    end repeat
end repeat
  • 1
    Can you please reduce your code to a usuable minimum which still shows the problem, and add any relevant input data to the question so others can reproduce what you are doing? Also add the exact error you get. – nohillside Dec 6 '19 at 15:01
  • The fact is that the code works, it performs its function, but not to the end as it should. The problem comes with filling the file. It fills in incorrect data. And what the problem is I can't figure out. Also, there you need to specify the coordinates of the mouse on the color of the wrong number. Therefore, only the code in full and it is possible to understand to play. @nohillside – MarshmallowRose Dec 6 '19 at 15:13
  • The input is a text file with numbers. Some are registered in imessage, some are not. By the color in which the number is painted, when inserted into the recipient window in the Message application from the source database, the registration is determined. You also need to set the position of the mouse in the code, in the place where it shows the color of this number. I could not implement a better solution. That's why I'm asking for help. @nohillside – MarshmallowRose Dec 6 '19 at 15:19
  • Well, as long as there is a problem it obviously doesn't work as expected. Anyway, please have a look at stackoverflow.com/help/minimal-reproducible-example to understand what changes are required. – nohillside Dec 6 '19 at 15:33
  • 1
    That is one hell of a rig moral to go through just to determine whether or not an iMessage number is viable. I presume you're creating the new iMessage and inputting the number from a script as well ? If it were me, I wouldn't check viability at that point - I'd go ahead and send the message. If the number isn't registered with iMessage, the message will fail to send, which will be printed in the message window. It's a lot more straight forward to detect whether "message failed to send" is printed in the message pane than detecting colours of pixels under a mouse cursor. – CJK Dec 7 '19 at 16:12
1

Rather than guess at what AppleScript is doing, have you considered running it in a debugger to know the variables as it runs and errors out?

Some things that make it hard to make a better answer are the parts where you say:

The main took with past issues on this site on this topic.

And

but apparently the wrong condition, apparently the wrong data types

And mostly

Some will insert, some will not, regardless of the initial condition. What could be the reason? Where is the error? And is it possible to make it so that after a certain number of verified numbers, he himself deleted open dialogs with these numbers?

Since you don’t post input values or share output values were really guessing even more than you. I would get into the debugger so you can see the flow.

| improve this answer | |
  • Those sentences you've quoted from the OP do not make any sense and why the question should be put on hold or closed until the post is rewritten in a comprehensible manner! – user3439894 Dec 7 '19 at 22:41
  • @user3439894 you have great points, nevertheless. I wanted to give them some help and possibly explain why questions like his get closed often quickly. Even if it gets closed, there’s a start to help OP and others... – bmike Dec 7 '19 at 23:45

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .