applescript send SMS message - macos

I am trying to send NEW messages using applescript through the macos messages app.
on run {targetBuddyPhone, targetMessage}
tell application "Messages"
send targetMessage to buddy targetBuddyPhone of service "SMS"
end tell
end run
The above script runs fine on the condition that there is already a conversation started for the specific targetBuddyPhone in the messages app. Any ideas how to send a NEW message?.. I can't believe it isn't possible.

It could be possible to call URL from Apple Script in this form:
sms://open?addresses=+15558675309,+15558675301/&body=Text%20Here%20end!
It will not send message, but just prefill it and user will need to press Enter key.

Related

Use Automator to send files via Messages App

I've seen some older posts about this issue but no real fixes.
I"m using macOS 13.1 and I would like to use Automator to send my clients iMessage or SMS texts that include images. I am able to send actual "text" just fine.
When I try to send a file, I see the file in the Messages app but I get a failed to send error. I see the same behavior using SMS or iMessage.
My simple Code
set image to POSIX file "/Path/To/File.ext"
tell application "Messages"
activate
set iMessageService to 1st account whose service type = iMessage
set client to participant "5551234567" of iMessageService
send image to client
end tell
Again, I can send texts to the same number but not a file. I am able to send the file to the number directly from the Messages app.
Google, Apple Developer, multiple phone numbers.

Simple AppleScript to send SMS by Messages app fails with error MacOs Monterey 12.0.1

I wish to automate the sending of SMS texts using AppleScript to control the Messages app in MacOS Monterey (12.0.1). My very simple test script fails with an error message as below:
tell application "Messages"
send "Test" to participant "123456789" of account "SMS"
end tell
Running the script fails with this error:
error "Messages got an error: Invalid key form." number -10002 from account "SMS"
Obviously, I am using a valid phone number (my own) which is among my contacts (in fact, Script Editor recognizes the number and offers additional info via a drop down list).
The MacBook Pro M1 I'm using is setup to send and receive text messages, I use that all the time. I get the same result if I try to send an iMessage by replacing "SMS" with "iMessage". Thank you for your help.
Try:
tell application "Messages"
launch
repeat while (count of windows) is 0
end repeat
set a to first account whose service type = SMS and enabled is true
set p to participant "123456789" of a
send "test, please ACK" to p
-- properties of p
end tell
Note: You may not be able to text yourself, and you may need to already have texted the recipient.
tell application "Messages"
set iMessageService to 1st account whose service type = iMessage
set imessagebuddy to participant "00301234567890" of iMessageService
send "ignore the last messages. just testing. i am still the applescriptmaster" to imessagebuddy
end tell

check if receiver number have iMessage enabled in apple script?

I am creating an apple script that will send iMessages to some numbers,
I want to check if those numbers have iMessage or not before sending it.
How could i achieve that in script editor? The following is the script to send the iMessage
tell application "Messages"
set theBuddy to buddy "the receiver number here" of service "my service"
send "Washer Done! :)" to theBuddy
end tell
still need to check if the receiver will be able to receive it or not before sending.
Any help?
Regards,

Scheduling an email to send in mail (mac)

I have an email that I need to schedule to send later. I know you can schedule an apple script to fire off at a set time using iCal, but I have been unable to find one that works. It doesn't necessarily have to be done this way though. I would be grateful of a solution to this problem.
This works for me with a run script alarm in iCal on 10.6.8
tell application "Mail"
activate
set mymail to make new outgoing message at the beginning of outgoing messages with properties {subject:"Triggered"}
tell mymail
make new to recipient at beginning of to recipients with properties {address:"first#email.com, second#email.com"}
set content to "hi"
end tell
--show message window (otherwise it's hidden)
set visible of mymail to true
--bring Mail to front
activate
send mymail
end tell
I'm also getting an error like outgoing message 1 doesn’t understand the send message when trying to send an outgoing message. Referring to a message created from a script still seems to work though.
tell application "Mail"
set m to make new outgoing message with properties {subject:"subject", content:"content"}
tell m
make new to recipient at end of to recipients with properties {address:"jana#doe.com, john#doe.com"}
end tell
send m
end tell
You could also create a Calendar alarm in Automator.
I just accomplished this without Automator, using only Apple Mail:
Double-click anywhere your calendar to start creating an event.
Give the event a name. This will be the subject line of the email.
Set the date and time of the event to when you want the email to be sent.
If you want the email to be sent on a schedule, choose a repeat frequency and potential termination date.
For the alert, choose Custom....
Select email. You might be prompted to add a contact card to the Contacts app.
Choose the person to whom you want to send the email, and set the time to At Time Of Event. Press OK.
You can choose to add Notes, a URL, or attachments. I haven't tried these options, but I assume that they are carried forward in the email that is sent.

Get contents of iChat message via Applescript

I'll preface this with the fact that I'm new to applescript...
I have iChat set up to run this script whenever a new message is received:
using terms from application "iChat"
on message received theMessage from theBuddy for theChat
set theHandle to handle of theBuddy
tell application "MyApp"
receivedInstantMessage from theHandle message theMessage
end tell
end message received
end using terms from
This works as expected an MyApp (which I'm coding) receives two strings (the handle of the buddy and the message content). The only trouble is that this script only seems to work once at least one message has been received in iChat. I.e the script seems to only work from the second message onwards. If the buddy logs out, he'll have to send two messages again before my app receives the AppleEvent.
Am I making a basic mistake here?
The first message is actually a "text invitation" so your notification script will need another handler:
on received text invitation theMessage from theBuddy for theChat
-- your tell app statement goes here
end received text invitation

Resources