Opening Messages programatically with pre filled fields on macOS

207 views Asked by At

I am trying to make QR codes actionable on macOS. I found that I can open Messages app just by using imessage as URI or sms as URI:

NSString *message = @"imessage://[email protected]";
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:message]];


NSString *message = @"sms://[email protected]";
[[NSWorkspace sharedWorkspace] openURL:[NSURL URLWithString:message]];

However I am not able to add any parameters so I can have pre fill body of the text. How to pre fill body?

sms URI is around only since 10.14 Mojave.

PS: Separating emails with comma for iMessage URI will do a group chat.

Messages.app method which handles URL (_handleGURL..) gets this NSAppleEventDescriptor:

(lldb) po $rdx
<NSAppleEventDescriptor: 'GURL'\'GURL'{ '----':"imessage://[email protected]", 'qtnp':'qtnd'($62706C6973743030D2010203045F10214C5351756172616E74696E654167656E7442756E646C654964656E7469666965725F10154C5351756172616E74696E654167656E744E616D655F1011636F6D2E6872756261736B6F2E7363616E50080D31495D000000000000010100000000000000050000000000000000000000000000005E$) }>

enter image description here

1

There are 1 answers

0
Marek H On

According to Starting a Chat from a URL of the Business Chat Framework:

There are optional query string parameters you can include in the URL: "biz-intent-id" "biz-group-id" "body"

NSURL *URL = [NSURL URLWithString:@"sms:[email protected]&body=Order%20additional%20credit%20card"];
[[NSWorkspace sharedWorkspace] openURL:URL];

However this doesn't work for iMessage URI (internal implementation sets nil for message value)

Messages app