2012-08-04 37 views
11

有人可以告訴我如何通過消息應用程序直接發送消息給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,卓悅沒有。 謝謝!

回答

32

而不必硬編碼的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 **自己**! – fabian789 2014-03-12 15:00:48

+0

@ fabian789謝謝你的提示。你知道解決這個限制的方法嗎?既然你可以發送一個iMessage給你自己(手動從Messages.app),是否沒有辦法通過腳本來做到這一點? – Chris 2014-04-08 10:46:15

+1

@Chris不,我不認爲這是可能的 – fabian789 2014-04-09 12:58:42

2

例子:

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]"

,我可以使用的「服務」的字符串。巴迪只是你的夥伴的名字,也是純文本。請參閱「獲取好友的名字」。

希望它的作品!

7

據我瞭解,你不能通過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://stackoverflow.com/questions/39027839 /如何開始新的對話在imessage-using-applescript。爲我工作 – mac 2016-09-09 12:40:04

+0

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

3
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帳戶成爲第一個帳戶。之後,這就像一個魅力。

這也將開始一個對話,如果沒有一個存在。

希望有幫助!

6

這個腳本會發出一個信息,每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://stackoverflow.com/questions/39027839/how-to-start-new-conversation-in-imessage-using-applescript – andi 2017-10-18 11:59:26

0

好吧,我只是做了如下成的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 
相關問題