2

我正在尝试检查不在我的联系人列表中的电话是否已在 iMessage 中注册。

我尝试过两种通用方法。

  1. 如果在好友列表中,则向电话号码发送消息
    
    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
    

为什么它不起作用?即使它可以通过删除“延迟 1”来发送消息,我也不想向用户发送垃圾邮件。延迟它只能检查我的好友(联系人)列表中的电话。

  1. 试图通过 UI 自动化获取按钮颜色。(手机未在 iMessage 中注册时按钮变为红色,否则为蓝色。)


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

我无法获得按钮颜色,因为它没有这样的属性。我还尝试从应用程序显示“+38093111111 未在 iMessage 中注册”的上下文菜单中获取数据,但我无法从 AppleScript 访问上下文菜单。

请帮助我完成我的使命:)

4

1 回答 1

-1

您可以通过在其上移动鼠标指针来获取按钮的颜色,然后编写应用程序 Digital Color Meter 的脚本。首先根据 iMessage 窗口上的一些 gui 元素,使用positionandsize属性计算按钮的 x 和 y 位置。
然后将指针移动到计算出的位置:

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 & "));\""

使用 Digital Color Meter 以 rgb 格式获取指向像素的颜色:

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
于 2015-03-13T19:05:54.227 回答