Apple script: How to get the message id of the currently selected message in outlook app - macos

I want to get the message id of the message currently open in outlook app during read mode in inbox on my mac using osa script.
so far I have tried this:
tell application "Microsoft Outlook"
set currentMessage to selection
set header to headers of currentMessage
end tell
And I got a response but headers do not have the message id
Mac OS Bir Sur, Apple M1
Outlook 16.46 Microsoft 365 subscription.

you should be able to:
get id of currentMessage
Works on Mojave with Outlook 16.44. (Exchange acct)

-- This works here:
tell application "Microsoft Outlook"
set currentMessage to selection
set thisID to id of currentMessage
get subject of message id thisID --> "test 1"
end tell

Related

AppleScript Seach Mail in Outlook with Exchange/Internet ID

I am handling Outlook emails using the MS Graph API and with the API, it provides the 'Email ID' and 'Internet Message ID' for each email. I want to be able then display a specific email in the Outlook App using the ID's I received from the API. This is for MacOS so I thought it may be possible with AppleScript.
Is it possible to search an outlook mail using the 'Email ID' or 'Internet Message ID'. It seems like the 'Email ID' value from the API and the 'exchange ID' in appleScript are similar, but different.
Exchange Id used in AppleScript vs Email Id from API. Different but very similar:
Exchange ID from AppleScript:
AAMkADc2YjQwNTdhLTJhYzItNDA0Ni04MmNhLTRlM2Q5MDMxMGI1NwBGAAAAAAD/aipfqmVySpN0sC+1eNHeBwANqnfaKK5URZoJzj79Kz7GAAAAAAEMAAANqnfaKK5URZoJzj79Kz7GAAAXVu7QAAA=
Email Id from MS API:
AAMkADc2YjQwNTdhLTJhYzItNDA0Ni04MmNhLTRlM2Q5MDMxMGI1NwBGAAAAAAD-aipfqmVySpN0sC_1eNHeBwANqnfaKK5URZoJzj79Kz7GAAAAAAEMAAANqnfaKK5URZoJzj79Kz7GAAATOkOyAAA=
This is what I have so far:
tell application "Microsoft Outlook"
set theFolder to mail folder "Inbox" of exchange account "<Account_Name>"
set theMsg to first message of theFolder whose exchange id is "<ID>"
open theMsg
end tell
Appreciate any ideas. Thanks!

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

Select mailbox for Microsoft Outlook when using Applescript

I'm using Applescript to automatically draft and send emails in Microsoft Outlook. While everything is working as expected to send emails from my own account, I want to adjust the script to send emails from a different account that I have access to in Outlook. I've found this post, but the approach shown there generates an error for me.
https://macscripter.net/viewtopic.php?pid=185222#p185222
How can I adjust the script below to select the correct mailbox to send my email from? When I use the script below, the following error is generated when I attempt to save it.
Syntax Error
Expected class name but found identified
I've Google this error message, but haven't been able to find anything relevant to my task of changing the account the email is sent from.
set theAccount to the first exchange account whose name is "second.account#company.com"
set recipientAddress to "first.last#company.com"
set theSubject to "This is only a test"
set theContent to "<html><body><p>This is only a test.</p></body></html>"
tell application "Microsoft Outlook"
set newMessage to make new outgoing message with properties {account:theAccount, subject:theSubject, content:theContent}
tell newMessage
make new recipient at newMessage with properties {email address:{address:recipientAddress}}
end tell
save in drafts
end tell

Using replay to all with Applescript and Outlook 2011

Right now I have a simple little AppleScript that will take the currently selected message and open a reply to window for the message.
I'm doing this to eliminate the default signature from the reply. For some reason Outlook 2011 does not have an option to exclude the signature on replies but using this script keeps the signature off.
Here's my script:
tell application "Microsoft Outlook"
set replyMessage to selection
set replyMessageSubj to subject of replyMessage
reply to replyMessage
end tell
tell application "Finder" to activate (every window whose name is "Re: " & replyMessageSubj)
That opens the replay window and activates it for me. Works well but I'd like to have it reply all, not just reply.
The dictionary for Outlook 2011 says:
reply to v : Create a reply message.
reply to message : The message to reply to.
[opening window boolean] : Should the reply message be opened in a window? Default is to show the window.
[reply to all boolean] : Whether to reply to all recipients of the message. Default it to reply to the sender only.
→ message : The reply message.
I'm a bit of an AppleScript novice and can't find a good example...
How do I get this to reply all?
Try:
tell application "Microsoft Outlook"
set replyMessage to selection
set replyMessageSubj to subject of replyMessage
reply to replyMessage with opening window and reply to all
end tell

Create new outgoing message with applescript in Microsoft Outlook

I'm trying to create a new outgoing message with Microsoft Outlook 2011 for mac, using AppleScript.
The following example worked in 10.6.8:
tell application "Microsoft Outlook"
set newMessage to make new outgoing message with properties {subject:"Hooray for automation"}
make new recipient at newMessage with properties {email address:{name:"Jim Shank", address:"jim.shank#example.com"}}
open newMessage
end tell
On Lion I'm getting the following error:
Microsoft Outlook got an error: Can’t make class outgoing message.
Does anybody have a clue what went wrong there?
I'm using offline Outlook.
Apparently, I'm using a trial version, that has expired. With registered version this script works perfectly. Boo Outlook...I spent on looking into this a couple of hours!
tell application "Microsoft Outlook"
set newMessage to make new outgoing message with properties {subject:"Hooray for automation"}
make new recipient at newMessage with properties {email address:{name:"Jim Shank", address:"jim.shank#example.com"}}
send newMessage
end tell
This way, it will automatically send it.

Resources