Skip to content

Instantly share code, notes, and snippets.

@brettcvz
Created March 20, 2015 02:40
Show Gist options
  • Save brettcvz/2c73176e49e079ab3d3e to your computer and use it in GitHub Desktop.
Save brettcvz/2c73176e49e079ab3d3e to your computer and use it in GitHub Desktop.
JS-Applescript to send iMessages
#!/usr/bin/env osascript -l JavaScript
function run(argv) {
var to = argv[0];
var msg = argv[1];
console.log("Sending message", "'" + msg + "'", "to", to);
messages = Application('Messages');
var service;
for (var i in messages.services) {
var s = messages.services[i];
var name = s.name();
if (name == "SMS") {
service = s;
console.log("Sending via SMS");
break;
} else if (name.substring(0,2) == "E:") {
service = s;
console.log("Sending via iMessage");
break;
}
}
recip = service.buddies[to];
messages.send(msg, {to: recip});
}
@micheleorsi
Copy link

Hi, I just found this script. I tested but I got always this list of services:

service: E:myicloudemail
service: SMS
service: Google
service: rumbo.com
service: Bonjour

How can I check if the user is available only on SMS or also on iMessage?
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment