Closed tomhardman0 closed 8 years ago
I think Apple changed the way that API works, since I haven't touched this code in a while (obviously). I'm in the middle of finals right now, but I can take a stab at updating this next week.
No problem - I ended up writing a very simple cli for imessaging/sms instead.
Good luck with your finals!
P.S. After reading around, it seems Apple removed the API for this in OSX 10.11!
I don't think the API has been removed..
I can still run this script in Script Editor:
var Messages = Application('Messages');
var recipient = Messages.buddies.whose({ handle: '<PHONE NUMBER>' })[0];
Messages.send('Hello?', { to: recipient });
And it works..
Try running imessage.send('Hello?', '<PHONE NUMBER>', callback);
and i get
execution error: Error on line 1: Error: Can't get object. (-1728)
Any ideas?
Turns out it is something to do with the +
character that gets trimmed off the phone number? "Can't get object." means that it can't find the buddy.
A work around is to pass the recipient object in as a whole. I.e:
imessage.send('Hello?', { handle: '+447000000000' }, callback);
It was the receiving messages API that got removed. Even Apple's official example of it is broken.
I wasn't aware that sending messages was broken as well. I'll take a look at that next week. (Funny how this project always gets attention during finals weeks)
Ah! To be honest, I thought this issue was about sending 🙄 Thanks for the info though and good luck with your finals!
Just an update for whoever might find this useful.. I noticed that the issue I am seeing is when trying to send a message to somebody where there is not yet a conversation in the Messages app.
I have however found another script from PieMessage that also sends a "service id" in the send command?
I don't know anything about applescript so was struggling to convert it into the osa javascript implementation (only just started playing with js recently too)...
Here is the script that does work anyway:
on run {msgText, targetPhoneNum}
tell application "Messages"
set serviceID to id of 1st service whose service type = iMessage
send msgText to buddy targetPhoneNum of service id serviceID
end tell
end run
(src)
It will probably be useful to somebody who can convert it into the js implementation and then fix any issues with this project..
I was trying to do something on the lines of var service = Messages.services.whose({ serviceType: 'iMessage' })[0];
but was running into issues when trying to pass it into Messages.send()
hope it helps :)
Sorry to leave you all hanging. I'm investigating the issues now.
Okay so I'm pretty sure I have the sending messages issue resolved. The receiving messages one could use some more looking in to
I'm fairly certain that Apple has stopped supporting the message handler Apple Script, meaning without major shifts in the way the code works, receiving messages will not be possible.
Using Apple's example script for the API yields this error.
If anyone finds new issues or discovers a solution to the receiving messages, feel free to open a new issue or PR.
Hi - I don't think you're maintaining this anymore but in case you are: I had this plugin working in Nov 2015 - no change has been made to my local implementation but it's stopped working sometime since then.
I haven't had time to dig into the code but let me know if there's a solution - I'd happily submit a PR.