24

有人可以告诉我如何通过消息应用程序直接向 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

我只需要通过 iMessage 向帐户发送消息,而不是通过 google talk、AIM、bonjour。谢谢!

4

6 回答 6

60

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

  1. 将以下脚本另存为sendMessage.applescript(注意:确保选择文本选项)。
  2. 通过运行执行它:osascript sendMessage.applescript 1235551234 "Hello there!"
  3. 这将向电话号码 123-555-1234 发送一条 iMessage,其中包含文本“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
于 2013-10-20T21:21:43.503 回答
11

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

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

tell application "Messages"
    get name of service of buddy "Buddy Name"
end tell

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

最后,您将能够发送消息

tell application "Messages"
    send "Text of Message" to buddy "+43 555 XXXXXXX" of service "E:example@mac.com"
end tell
于 2013-01-22T23:33:28.900 回答
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
于 2014-05-12T22:17:18.670 回答
4
tell application "Messages"
    set myid to get id of first service
    set theBuddy to buddy "mybuddy@me.com" of service id myid
    send "Washer Done!" to theBuddy
end tell

我有同样的问题,经过一番搜索,我找到了答案。为了让“第一个服务”成为 iMessage,您需要进入 iMessage Preferences Accounts 并将 iMessage 帐户重新排序为第一个。之后,这就像一个魅力。

如果没有对话,这也将开始对话。

希望有帮助!

于 2013-06-03T22:32:16.170 回答
3

例子:

get services
get name of services
get buddies
get name of buddies 

您的线路:

send "Test-Message" to buddy "buddy" of service "service"

如果“伙伴”和“服务”有效,似乎可以工作。

我的 iMessage 注册了我的 Apple-ID,所以当我执行“获取服务名称”时,我会为此服务获得一个字符串,例如

“E:myAppleID@host.com”

我可以将其用于“服务”。Buddy 只是你的好友的名字,也是纯文本。请参阅“获取好友的姓名”。

希望它有效!

于 2012-08-19T23:59:33.567 回答
0

好的,我刚刚将以下内容放入 Automator 操作中,该操作获取登录用户的全名,从联系人中找到匹配的 iPhone 号码、服务名称,最后将传入文本(来自上一个操作)发送到.. .myself 在 iMessage 上。不是很有用,至少目前对我来说不是很有用,但我证明它在某种程度上是可能的:)

set input to "Testing 123" **//This line is just for testing**
tell application "System Events"
    set MyName to get full name of current user
end tell
  tell application "Contacts"
      set myPhone to value of phone 1 of (person 1 whose name = MyName)   
      whose label = "iPhone"
   end tell
tell application "Messages"
    set MyService to get name of service of buddy MyName
    send input to buddy myPhone of service MyService
end tell
于 2015-09-22T20:25:41.093 回答