【问题标题】:How to send an imessage text with applescript, only in provided service?如何仅在提供的服务中使用 applescript 发送 imessage 文本?
【发布时间】:2012-08-02 11:22:26
【问题描述】:

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

【问题讨论】:

    标签: applescript send messages imessage


    【解决方案1】:

    例子:

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

    您的线路:

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

    如果“buddy”和“service”有效,似乎可以工作。

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

    “E:myAppleID@host.com”

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

    希望它有效!

    【讨论】:

      【解决方案2】:

      据我所知,您无法通过 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
      

      【讨论】:

      【解决方案3】:
      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 帐户重新排序为第一个。之后,这就像一个魅力。

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

      希望有帮助!

      【讨论】:

        【解决方案4】:

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

        1. 将以下脚本另存为sendMessage.applescript(注意:确保选择Text选项)。
        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
        

        【讨论】:

        • @fabian789 感谢您的提示。你知道绕过这个限制的方法吗?既然您可以向自己发送 iMessage(从 Messages.app 手动发送),有没有办法通过脚本来做到这一点?
        • @Chris 不,我认为这不可能
        • @fabian789 是的,你可以
        • @fabian789 我尝试发送到我的 iCloud 电子邮件,并收到错误 Messages got an error: Can't send a message to yourself. 所以我只是尝试发送到我的 iMessage 的另一个别名,就像我的电话号码一样,它成功了。
        • 想提请您注意我提出的问题500积分赏金stackoverflow.com/questions/39027839/…
        【解决方案5】:

        此脚本将每 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
        

        【讨论】:

        【解决方案6】:

        好的,我刚刚将以下内容添加到 Automator 操作中,该操作获取登录用户的全名,从联系人中找到匹配的 iPhone 号码、服务名称,最后发送传入文本(来自上一个操作)给...我自己在 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
        

        【讨论】:

          猜你喜欢
          • 2013-04-04
          • 2019-03-31
          • 2018-08-09
          • 2018-06-28
          • 2016-03-14
          • 2012-11-16
          • 2018-06-13
          • 2016-12-25
          相关资源
          最近更新 更多