While playing around with Messages this morning, I noticed that it ships with a feature that, if used, throws an error. Steps to reproduce:
Open Messages' preferences.
Set the Applescript handler pop-up to any of the listed scripts:
Close preferences, and try to send a message to anyone.
Revel in the brokenness.
I especially like the execution error: No error message…it's that rare non-error that tosses up an error dialog!
In any event, I think it's shameful that Apple ships the app with a feature—plainly obvious in prefs—that breaks when used. Yes, I know AppleScript is probably dying, but that doesn't excuse shipping the app with a clearly-broken feature; if it doesn't work, just remove it. Apparently this has been an issue since Yosemite's release in October of 2014!
With all that said, fixing this is incredibly easy—it took me about 30 seconds of "work" to find and fix the problem. If you'd like to use the bundled AppleScripts in Messages—either as is, or in some modified form—here's what you need to do
In Messages' prefs, select Open Scripts Folder from the AppleScript handler pop-up. Now open all six scripts in Script Editor (in Applications > Utilities). Find these four lines in each Apple-provided script (note I've removed the silly whitespace Apple included):
on received remote screen sharing invitation from theBuddy for theChat end received remote screen sharing invitation on received local screen sharing invitation from theBuddy for theChat end received local screen sharing invitation
To fix the scripts, comment those lines out, which you do in AppleScript with two hyphens. After editing, that section should look like this:
--on received remote screen sharing invitation from theBuddy for theChat --end received remote screen sharing invitation --on received local screen sharing invitation from theBuddy for theChat --end received local screen sharing invitation
Save the modified scripts, and the error message will vanish when you select a script in Messages' preferences. I tested with the iTunes Remote Control script, and it worked fine after making the above edits. (Note for it to work, the chat that's sending the iTunes commands can't be the frontmost chat. If testing with a buddy, switch to another chat before they send the controlling commands.)
I assume there's probably a better fix—those commands I commented out have probably been renamed—but I didn't bother spending any time looking for that fix, because I'm not getting paid to fix Apple's problems.
I seem to have only 5 AppleScripts in the folder:
iTunes Remote Control.applescript
Mix Message Case.applescript
Did you create the Alert on Available script?
I did - that's what actually started me on this route. This used to be a standard feature, but it went away when Apple decided always-on Messages was the thing to have. I was trying to recreate it, though never got it to work.
Error -1708 means a command couldn't be handled. AppleScript is hopelessly vague about where an error originated (no such thing as stack traces), so you need to make sure it's not being caused by any of the commands your script sends itself, but from your description I reckon it's the initial
received remote screen sharing invitationcommand that's sent by Messages to your script that's not being handled.
I don't use Messages myself, but from what I remember of Mail action scripts, the Mail devs designed it so that if your attached script defined a
perform mail action with messageshandler, Mail would call that, passing a list of messages and other information for your handler to work with. If the attached script doesn't contain that handler, Mail just sends a basic
runcommand that executes any top-level statements in your script, which is fine if you don't care about the details.
Sounds like the Messages devs have taken the same approach, only they've screwed up the implementation that causes the
perform mail action with messagesnotification to miss your script's
perform mail action with messageshandler. It's probably a really stupid trivial bug too, such as the ObjC code that sends the
received remote screen sharing invitationcommand to the script not using the exact four-char codes given in Messages' dictionary. In which case it's a 30-second fix, not counting the years of bureaucracy it takes to action it first!
Thanks for this. I has successfully got my Messages speaking received iMessages but not received SMS messages. Is there any way to get it to speak SMS messages as well?
It should work via SMS by default. Just enter someone's phone number to send them a message.
Sorry, I should have specified: I'm referring to the Speak Events.applescript. It wouldn't work until I modified it as you said above. Now it speaks iMessages I receive in Messages (blue) but does not speak any SMS messages I receive (green).
Ah, sorry ... not sure. Perhaps SMS don't trigger the same event notifications as do actual iMessages? I really don't have a clue. Looking at the code, there's nothing there to distinguish message types - the one line that does the speaking on a received message is "say eventDescription," so maybe that field is blank (somehow) for SMS?
No worries, just thought I'd check. Thanks anyway.
Comments are closed.