Hi,
I want to use the scripting functions of message.app to forward incoming messages by mail.
That works fine with this script, added within the properties of messages.app. I’ve added an protocol-handler in the script, writes every call of the Messages.app event handler to a file on the desktop:
using terms from application "Messages"
--create a text protocol
on WriteLog(LogText)
set LogFile to POSIX path of (((path to desktop) as string) & "message.app_eventprotocol_" & short date string of (current date) & ".txt")
do shell script "echo " & quoted form of ((do shell script "date \"+%Y-%m-%d %H:%M:%S \"") & tab & LogText) & " >> " & LogFile
end WriteLog
--message.app events
on message received MessageText from MessageBuddy for MessageChat
set ReceivedText to MessageText
set ReceivedBuddy to name of MessageBuddy as text
--add any action: e.g Log informations, create Mail, save to a database ...
WriteLog("message received" & " ¢¢¢ " & ReceivedBuddy & " ¢¢¢ " & ReceivedText)
end message received
on message sent MessageText for MessageChat
WriteLog("message sent" & " ¢¢¢ " & " ¢¢¢ " & MessageText)
end message sent
on active chat message received
WriteLog("active chat message received")
end active chat message received
on chat room message received MessageText from MessageBuddy for MessageChat
WriteLog("message received" & " ¢¢¢ " & (name of MessageBuddy as text) & " ¢¢¢ " & MessageText)
end chat room message received
on addressed chat room message received MessageText from MessageBuddy for MessageChat
WriteLog("addressed chat room message received" & " ¢¢¢ " & (name of MessageBuddy as text) & " ¢¢¢ " & MessageText)
end addressed chat room message received
on addressed message received MessageText from MessageBuddy for MessageChat
WriteLog("addressed message received" & " ¢¢¢ " & (name of MessageBuddy as text) & " ¢¢¢ " & MessageText)
end addressed message received
on av chat started
WriteLog("av chat started")
end av chat started
on av chat ended
WriteLog("av chat ended")
end av chat ended
on login finished for MessageService
WriteLog("login finished")
end login finished
on logout finished for MessageService
WriteLog("logout finished")
end logout finished
on buddy became available MessageBuddy
WriteLog("buddy became available" & " ¢¢¢ " & (name of MessageBuddy as text))
end buddy became available
on buddy became unavailable MessageBuddy
WriteLog("buddy became unavailable" & " ¢¢¢ " & (name of MessageBuddy as text))
end buddy became unavailable
on completed file transfer
WriteLog("completed file transfer")
end completed file transfer
end using terms from
But it works only for “iMessage”-messages, not for “SMS”-messages. I’ve connected my iPhone to the Mac with handoff and SMS-messages also appears on the Mac. But nothing is happen with such messages, the script registered no event.
Looking for the kind auf the SMS-chats works, this script also shows the connected services (it doesn’t show an SMS-service):
tell application "Messages"
set MyServicesNames to name of every service
(* Sample-Output:
{"E:mymailname@me.com", "Bonjour", "Bonjour"}
*)
set MessagesChats to (get every chat)
(* Sample-Output:
{text chat id "iMessage;+;chat874940696517123456" of application "Messages", ¬
text chat id "iMessage;+;chat716649889161234567" of application "Messages", ¬
text chat id "SMS;-;+491621234567" of application "Messages", ¬
text chat id "SMS;-;+49169876543" of application "Messages"}
*)
end tell
I’ve studied the dictionary of Messages.app but have no idea, how I can get new SMS-messages to work with.
Please help.
Rebewslin