Reputation: 1802
I'm looking for a way to find out that if a number has registered in iMessage or not. So far I know how to send a message using this script:
set number to "+111111111111"
set message to "Test"
tell application "Messages"
set targetServise to 1st service whose service type = iMessage
set targetBuddy to buddy number of targetService
delay 1
if targetBuddy exists then
send message to targetBuddy
end if
#delay 5
end tell
All I need now, is to know whether this number has been registered in iMessage or not?
P.S: Is there any kind of API for that?
Upvotes: 1
Views: 1975
Reputation: 1878
Your script will work correctly if you use, for example, phoneNumber instead of the number variable. And that's because the number keyword is reserved in the AppleScript language to denote the abstract class "number". Just don't use it and you will get what you are looking for.
Simple handler to check if the buddy (of service iMessage) with indicated phone number exists:
on buddyExists(phoneNumber)
tell application "Messages"
set targetBuddy to buddy phoneNumber of (1st service whose service type = iMessage)
targetBuddy exists
end tell
end buddyExists
buddyExists("+111111111111")
Upvotes: 0