发送imessage消息

on send_msg(msg, PhoneNum, Ui)
    tell application "Messages"
        activate
    end tell
    if Ui is equal to false then
        tell application "Messages"
            set targetService to 1st service whose service type = iMessage
            set targetBuddy to buddy PhoneNum of targetService
            send msg to targetBuddy
        end tell
    else
        set the clipboard to msg
        tell application "System Events"
            keystroke "n" using {command down}
            delay 0.8
            keystroke PhoneNum
            delay 0.8
            keystroke return
            delay 0.5
            keystroke "v" using command down
            keystroke return
        end tell
    end if
end send_msg

on run {}
    set msg to "hello world"
    set PhoneNum to "180xxx"
    set Ui to true
    send_msg(msg, PhoneNum, Ui)
end run
原文地址:https://www.cnblogs.com/dockers/p/10869098.html