Can somebody show me how to send a message directly to the user of iMessage via Messages app?
tell application "Messages"
if service type of service of buddy whose name is ("Name here" is "iMessage") then set x to 1
if service type of service of buddy whose name is ("Name here" is "iMessage") then set x to 2
if service type of service of buddy whose name is ("Name here" is "iMessage") then set x to 3
send "Message" to buddy "mail of name" of service x
end tell
I need to send a message to an account only via iMessage, not via google talk, AIM, bonjour.
Thank you!
Instead of having to hard-code the iMessage service, you can find it automatically:
Save the following script as sendMessage.applescript (Note: make sure to choose the Text option).
Execute it by running: osascript sendMessage.applescript 1235551234 "Hello there!".
This will send an iMessage to the phone number 123-555-1234 containing the text "Hello there!".
sendMessage.applescript:
on run {targetBuddyPhone, targetMessage}
tell application "Messages"
set targetService to 1st service whose service type = iMessage
set targetBuddy to buddy targetBuddyPhone of targetService
send targetMessage to targetBuddy
end tell
end run
As far as I do understand it you cannot start a new conversation via AppleScript. Thus the Buddy and the service must fit together and must have an ongoing conversation.
If you have the name of the buddy you could do the following
tell application "Messages"
get name of service of buddy "Buddy Name"
end tell
This will return the service name that fits to the buddy. Of course you could also use the the service id. But I like to use the name.
In the end you will be able to send a message with
tell application "Messages"
send "Text of Message" to buddy "+43 555 XXXXXXX" of service "E:example#mac.com"
end tell
This script will send a message every 10~30 seconds
tell application "Messages"
set targetBuddy to "+12025551234"
set targetService to id of 1st service whose service type = iMessage
repeat
set textMessage to "Hi there!"
set theBuddy to buddy targetBuddy of service id targetService
send textMessage to theBuddy
delay (random number from 10 to 30)
end repeat
end tell
tell application "Messages"
set myid to get id of first service
set theBuddy to buddy "mybuddy#me.com" of service id myid
send "Washer Done!" to theBuddy
end tell
I had the same question and after some searching I found the answer. In order for the "first service" to be iMessage you will need to go into iMessage Preferences Accounts and re-order the iMessage account to be the first one. After that this works like a charm.
This will also start a conversation if there is not one existing.
Hope that helps!
Examples:
get services
get name of services
get buddies
get name of buddies
Your line:
send "Test-Message" to buddy "buddy" of service "service"
seems to work if "buddy" and "service" is valid.
I have my iMessage with my Apple-ID registered, so when I execute "get name of services" I get for this service a string like
"E:myAppleID#host.com"
which I can use for "service". Buddy is just the name of your buddy, also as pure text. See "get name of buddies".
Hope it works!
Ok, I just made the following into an Automator action which grabs the logged in userĀ“s full name, finds the matching iPhone number from Contacts, the service name, and lastly it sends the incoming text (from the previous action) to...myself on iMessage. Not very useful, at least to me at the moment, but I proved it to be possible in a way :)
set input to "Testing 123" **//This line is just for testing**
tell application "System Events"
set MyName to get full name of current user
end tell
tell application "Contacts"
set myPhone to value of phone 1 of (person 1 whose name = MyName)
whose label = "iPhone"
end tell
tell application "Messages"
set MyService to get name of service of buddy MyName
send input to buddy myPhone of service MyService
end tell
Related
I am trying to send a url with a thumbnail in applescript like this:
on run {targetBuddyPhone, targetMessage}
tell application "Messages"
set targetService to 1st service whose service type = iMessage
set targetBuddy to buddy targetBuddyPhone of targetService
send "Check out my video https://www.example.com" to targetBuddy
end tell
end run
The problem is that link is not clickable. How do I enter a url so that a thumbnail shows up like when a link is sent in a typical iMessage.
So I have this AppleScript
set filePath to (path to desktop as text) & "photo.png"
tell application "Messages"
set targetService to 1st account whose service type = iMessage
set targetBuddy to participant "+18005555555" of targetService
send file filePath to targetBuddy
end tell
worked before but in macOS 12 it looks like it's working (see the progress bar) but eventually timesout and states it can't be sent.
Is there an update to sending this?
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
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.
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,