MacOS. How to programmatically check a new SMS message? - macos

I want to periodically programmatically check whether a new SMS message has arrived from a specific sender. If it came, then I want to copy text the text to the clipboard.
using terms from application "Messages"
on message received theMessage from theBuddy for theChat with eventDescription
set the clipboard to theMessage
end message received
end using terms from

Related

How to set sender in Outlook POP account using AppleScript?

This script selects my main account and the signature related to it.
tell application "Microsoft Outlook"
set theContent to "Mail Content etc."
set theMessage to make new outgoing message with properties {subject:(("Month ") & (do shell script "date '+%m'")), content:theContent}
make new recipient with properties {email address:{address:"to#mail.com"}} at end of to recipients of theMessage
make new recipient with properties {email address:{address:"to#mail.com"}} at end of cc recipients of theMessage
open theMessage
end tell
I would like to add a line that picks one of several POP accounts to send from.
Ideally the resulting mail has the signature stored under that address.

How to add an attachment to an email reply with AppleScript

The code below allows me to create an email reply:
tell application "Mail"
set theAttachmentFile to "path"
set theMessages to the selected messages of the front message viewer
set theMessage to first item of theMessages
set theOutgoingMessage to reply theMessage with opening window and
reply to all
end tell
in this situation I'm not able to add an attachment file to the replay front message. In what way can i do that? Is it possible?
Thanks!

Active Chat Received Message Applescript Handler gets runs twice, anybody know why?

Please can anyone help me with the below issue:
Active Chat Message Handler in Applescript for Messages app runs twice, looks like it receives the message twice, has anyone else seen this issue?
below is my code:
global myBuddysName
global textmsg
on readFile(unixPath)
set foo to (open for access (POSIX file unixPath))
set txt to paragraphs of (read foo for (get eof foo))
close access foo
return txt
end readFile
on msgImage(unixPath)
tell application "Finder"
set randomFile to (some file of folder unixPath)
set the clipboard to (randomFile as «class furl»)
end tell
tell application "System Events"
keystroke "v" using command down
key code 36
end tell
end msgImage
using terms from application "Messages"
on message received theMessage from theBuddy for theChat
set myBuddysName to 1st item of readFile("Users/username/Desktop/AutomatedTextReply/BuddyName.txt")
set textmsg to some item of readFile("Users/username/Desktop/AutomatedTextReply/Texts.txt")
if name of theBuddy is myBuddysName then
if theMessage contains "text" then
send textmsg to theBuddy
end if
if theMessage contains "image" or theMessage contains "img" then
msgImage("Macintosh HD:Users:username:Desktop:AutomatedTextReply:Images")
delay (5)
end if
if theMessage contains "video" then
msgImage("Macintosh HD:Users:usernameDesktop:AutomatedTextReply:Videos")
end if
end if
end message received
on message sent theMessage with eventDescription
end message sent
on chat room message received with eventDescription
end chat room message received
on active chat message received theMessage from theBuddy
set myBuddysName to 1st item of readFile("Users/username/Desktop/AutomatedTextReply/BuddyName.txt")
set textmsg to some item of readFile("Users/username/Desktop/AutomatedTextReply/Texts.txt")
if name of theBuddy is myBuddysName then
if theMessage contains "text" then
send textmsg to theBuddy
end if
if theMessage contains "image" or theMessage contains "img" then
msgImage("Macintosh HD:Users:username:Desktop:AutomatedTextReply:Images")
delay (5)
end if
if theMessage contains "video" then
msgImage("Macintosh HD:Users:username:Desktop:AutomatedTextReply:Videos")
end if
end if
end active chat message received
on addressed message received theMessage from theBuddy for theChat with eventDescription
end addressed message received
on received text invitation with eventDescription
end received text invitation
on received audio invitation theText from theBuddy for theChat with eventDescription
end received audio invitation
on received video invitation theText from theBuddy for theChat with eventDescription
end received video invitation
on received local screen sharing invitation from theBuddy for theChat with eventDescription
end received local screen sharing invitation
on buddy authorization requested with eventDescription
end buddy authorization requested
on addressed chat room message received with eventDescription
end addressed chat room message received
on received remote screen sharing invitation with eventDescription
end received remote screen sharing invitation
on login finished with eventDescription
end login finished
on logout finished with eventDescription
end logout finished
on buddy became available with eventDescription
end buddy became available
on buddy became unavailable with eventDescription
end buddy became unavailable
on received file transfer invitation theFileTransfer with eventDescription
end received file transfer invitation
on av chat started with eventDescription
end av chat started
on av chat ended with eventDescription
end av chat ended
on completed file transfer with eventDescription
end completed file transfer
end using terms from
Looks like the both handlers on message received theMessage from theBuddy for theChat and on active chat message received theMessage from theBuddy are called. Comment the second handler using (* and *) and try again. If it works as wanted keep the changes ;-)
Have fun, Michael / Hamburg

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,

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