如何使用applescript发送imessage文本,仅在提供的服务中发送?

cre*_*eve 18 applescript messages send imessage

有人可以告诉我如何通过消息应用程序直接向iMessage用户发送消息吗?

tell application "Messages"
    if service type of service of buddy whose name is ("Name here" is "iMessage") then set x to 1
    if service type of service of buddy whose name is ("Name here" is "iMessage") then set x to 2
    if service type of service of buddy whose name is ("Name here" is "iMessage") then set x to 3

    send "Message" to buddy "mail of name" of service x
end tell
Run Code Online (Sandbox Code Playgroud)

我只需要通过iMe​​ssage向帐户发送消息,而不是通过Google Talk,AIM,bonjour.谢谢!

Sen*_*ful 46

您无需对iMessage服务进行硬编码,而是可以自动找到它:

  1. 将以下脚本另存为sendMessage.applescript(注意:确保选择" 文本"选项).
  2. 通过运行:执行它osascript sendMessage.applescript 1235551234 "Hello there!".
  3. 这将发送一个iMessage到电话号码123-555-1234,其中包含文本"Hello there!".

sendMessage.applescript:

on run {targetBuddyPhone, targetMessage}
    tell application "Messages"
        set targetService to 1st service whose service type = iMessage
        set targetBuddy to buddy targetBuddyPhone of targetService
        send targetMessage to targetBuddy
    end tell
end run
Run Code Online (Sandbox Code Playgroud)

  • @fabian789 我尝试发送到我的 iCloud 电子邮件,并收到错误“消息出错:无法向自己发送消息。”所以我只是尝试发送到我的 iMessage 的另一个别名,例如我的电话号码,它工作了。 (3认同)

小智 10

据我所知,你无法通过AppleScript开始新的对话.因此,好友和服务必须结合在一起,并且必须进行持续的对话.

如果您有好友的名字,您可以执行以下操作

tell application "Messages"
    get name of service of buddy "Buddy Name"
end tell
Run Code Online (Sandbox Code Playgroud)

这将返回适合好友的服务名称.当然,您也可以使用服务ID.但我喜欢用这个名字.

最后,您将能够发送消息

tell application "Messages"
    send "Text of Message" to buddy "+43 555 XXXXXXX" of service "E:example@mac.com"
end tell
Run Code Online (Sandbox Code Playgroud)


Vit*_*.us 7

此脚本将每隔10~30秒发送一条消息

tell application "Messages"

    set targetBuddy to "+12025551234"
    set targetService to id of 1st service whose service type = iMessage

    repeat

        set textMessage to "Hi there!"

        set theBuddy to buddy targetBuddy of service id targetService
        send textMessage to theBuddy

        delay (random number from 10 to 30)

    end repeat

end tell
Run Code Online (Sandbox Code Playgroud)