如何仅通过提供的服务发送带有AppleScript的imessage文本?

问题描述:

有人可以告诉我如何通过消息应用程序直接发送消息给iMessage的用户吗?如何仅通过提供的服务发送带有AppleScript的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发送消息到帐户,通过谷歌对话,AIM,卓悦没有。 谢谢!

而不必硬编码的iMessage服务,可以自动找到它:

  1. 将以下脚本保存为sendMessage.applescript(注:一定要选择文本选项)。
  2. 通过运行执行它:osascript sendMessage.applescript 1235551234 "Hello there!"
  3. 这将发送一个iMessage到电话号码123-555-1234包含文字“你好!”。

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 
+3

注:你不能iMessage **自己**! – f*789 2014-03-12 15:00:48

+0

@ f*789谢谢你的提示。你知道解决这个限制的方法吗?既然你可以发送一个iMessage给你自己(手动从Messages.app),是否没有办法通过脚本来做到这一点? – Chris 2014-04-08 10:46:15

+1

@Chris不,我不认为这是可能的 – f*789 2014-04-09 12:58:42

例子:

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

你行:

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

似乎工作,如果 “好友”, “服务” 是有效的。

我有我的iMessage与我的苹果ID注册,所以当我执行“获得服务的名称为”我得到这个服务就像

"E:[email protected]"

,我可以使用的“服务”的字符串。巴迪只是你的伙伴的名字,也是纯文本。请参阅“获取好友的名字”。

希望它的作品!

据我了解,你不能通过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:[email protected]" 
end tell 
+1

要开始一个新的对话,按照此 - http://*.com/questions/39027839 /如何开始新的对话在imessage-using-applescript。为我工作 – mac 2016-09-09 12:40:04

+0

@mac这是行不通的.. – andi 2017-10-16 22:40:27

tell application "Messages" 
    set myid to get id of first service 
    set theBuddy to buddy "[email protected]" of service id myid 
    send "Washer Done!" to theBuddy 
end tell 

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

这也将开始一个对话,如果没有一个存在。

希望有帮助!

这个脚本会发出一个信息,每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 
+0

你可以看看https://*.com/questions/39027839/how-to-start-new-conversation-in-imessage-using-applescript – andi 2017-10-18 11:59:26

好吧,我只是做了如下成的Automator动作,其抓住登录user's全名,从联系人中找到匹配的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