« Extra sight seeing fo… | Home | MBS FileMaker Plugin,… »

Send text message from FileMaker via iMessage

A client recently asked how to send text messages (SMS) via iMessage. Instead of using a web service of some provider, he only has to occasionally send a few messages automated over his iPhone. So we got the following AppleScript for him:

 

property targetPhone : ""

property targetMessage : ""

 

on run

tell application "Messages"

set targetService to 1st service whose service type = iMessage

set targetBuddy to buddy targetPhone of targetService

send targetMessage to targetBuddy

end tell

end run

 

This script has two properties for the phone number (or email) and the message to send. The script asks Messages app on MacOS for the first service for iMessage and for the buddy with the given phone number. Than it sends a message to the buddy.

We use properties for such scripts, because we can compile the AppleScript once and pass data to the script by setting the properties. No escaping needed, no change in the script with place holders, but directly write values in the properties and run the script again.

 

In FileMaker we got the following script to compile the AppleScript, set properties and run it. As you see we store reference to compiled script in $$scriptID and only compile once.

 

If [ $$scriptID = "" ] 

Set Variable [ $$scriptID ; Value: MBS( "Applescript.Compile"; AppleScript Properties::AppleScriptCode ) ] 

If [ MBS("isError") ] 

Show Custom Dialog [ MBS("AppleScript.LastErrorMessage") ] 

Exit Script [ Text Result:    ] 

End If

End If

Set Variable [ $r ; Value: MBS( "Applescript.SetPropertyValue"; $$scriptID; "targetPhone"; AppleScript Properties::targetPhone) ] 

Set Variable [ $r ; Value: MBS( "Applescript.SetPropertyValue"; $$scriptID; "targetMessage"; AppleScript Properties::targetMessage) ] 

Set Variable [ $r ; Value: MBS( "Applescript.Execute"; $$scriptID) ] 

 

Please do not hesitate to contact us if you have any questions.

10 03 19 - 12:47