Hi KM community,
It seems that Support for AppleScript in the New Outlook for Mac is now available. Does anyone have some scripts or know where to find informations about this?
Thanks,
Bruno
Hi KM community,
It seems that Support for AppleScript in the New Outlook for Mac is now available. Does anyone have some scripts or know where to find informations about this?
Thanks,
Bruno
Unless they made a metric shedload of other changes -- New Outlook probably still sucks, so I'm sticking to Old for now...
But it's very likely that they've re-implemented what was previously there (minus the still-missing features) so previous scripts/techniques are still valid. Is there something particular you are trying to do, or are just looking for general tips and tricks?
The more relevant scritps for my workflows are send message to DevonThink, to Omnifocus creating tasks and download message.
I have already some but I get errors handling the messages.
Thanks for the help.
Here's a couple of send examples. The first will activate Outlook and leave the message open so you can check before sending:
set msgContent to "Hello World!"
set theAddress to "example@example.com"
tell application "Microsoft Outlook"
activate
set theAccount to the first exchange account whose full name contains "Nige_S"
set newMsg to make new outgoing message with properties {account:theAccount, subject:"Let's send an email!", plain text content:msgContent}
make new recipient at newMsg with properties {email address:{address:theAddress}}
open newMsg
end tell
This one will send in the background, without intervention:
set msgContent to "Hello World!"
set theAddress to "example@example.com"
tell application "Microsoft Outlook"
set theAccount to the first exchange account whose full name contains "Nige_S"
set newMsg to make new outgoing message with properties {account:theAccount, subject:"Let's send an email!", plain text content:msgContent}
make new recipient at newMsg with properties {email address:{address:theAddress}}
send newMsg
end tell
As you can see, they follow the same general format -- make a new outgoing message
, set its properties, open or send the message. I need the first account
line because I have multiple Exchange accounts -- YMMV.
Do you mean "Save As..." to disk? This will save the selected message(s) to your Desktop folder:
tell application "Microsoft Outlook"
set selectedMsgs to the selection
if class of selectedMsgs is not list then set selectedMsgs to {selectedMsgs}
repeat with eachMsg in selectedMsgs
save eachMsg in alias "Macintosh HD:Users:Nige_S:Desktop"
end repeat
end tell
...but you'll have to change the alias
path to suit your setup.
Note that these are quick hacks/edits for this post, so lack error-checking! Speaking of which...
Post a sample script and the error you are getting -- I'm sure someone can help.
Thanks @Nige_S
I get the following error in the New Outlook: "One or more messages must be selected."
tell application "Microsoft Outlook"
try
set theSelection to the selected objects
if theSelection is {} then error "One or more messages must be selected."
tell application id "DNtp"
if not (exists current database) then error "No database is in use."
set theGroup to preferred import destination
end tell
repeat with theMessage in theSelection
try
set theSubject to subject of theMessage
set theSender to sender of theMessage
set theSender to (address of theSender) as string
set theSource to source of theMessage
set theDateReceived to time received of theMessage
set theDateSent to time sent of theMessage
if theSubject is equal to "" then set theSubject to pNoSubjectString
set theCategories to {}
set theList to (category of theMessage)
repeat with theCategory in theList
set theCategories to theCategories & (name of theCategory)
end repeat
set isFlagged to true
if todo flag of theMessage is (not flagged) then set isFlagged to false
set isUnread to is read of theMessage
tell application id "DNtp"
set theRecord to create record with {name:theSubject & ".eml", type:unknown, creation date:theDateSent, modification date:theDateReceived, URL:theSender, source:(theSource as string)} in theGroup
if theCategories is not {} then
set theTags to tags of theRecord
set theTags to theTags & theCategories
set tags of theRecord to theTags
end if
if isFlagged then set state of theRecord to true
if isUnread then set unread of theRecord to true
perform smart rule trigger import event record theRecord
end tell
end try
end repeat
on error error_message number error_number
if the error_number is not -128 then display alert "Outlook" message error_message as warning
end try
end tell```
Then -- and assuming you do have something selected in the Main window -- it looks like they haven't fully implemented AS yet. (This page suggests it is still in testing, not roll-out.)
Try the following in Script Editor/Debugger, with a message selected in Outlook:
tell application "Microsoft Outlook"
return the selected objects
end
...and:
tell application "Microsoft Outlook"
return the selection
end
What do you get for each?
I'm also stuck using Outlook here at work and have been looking for a way to add a keyboard shortcut that opens a saved search. No luck there b/c of the half-hearted AppleScript implementation. Anyway, your first script returns {}
and the second missing value
.
This does nothing
this returns the same error
Me too. But, unless work is preventing it for some reason, you can always knock it back to "Old" or "Legacy" Outlook to get back AppleScript support. How you do that depends, because they keep moving the option around the menus/settings -- probably to make it look like we all love the new version and don't want to go back.
I'm having no trouble accessing Shared Mailboxes etc when other people are using New Outlook, and the only annoyance is that I keep showing them how to do something in "Old" Outlook, only to find it's still missing (but promised "soon") in "New".
Looks like any news of the return of AS support was premature. But if it's in testing now, hopefully it'll be rolled out before too long.
hope so....
Hello, community!
I’m raising a topic here, and a little bit of background about my issue.
I’ve successfully written and implemented automatic email creation from Excel (VBS) to Outlook on Windows, and it works great. Now, I need to achieve the same thing on Mac, but I'm facing some difficulties.
The task is simple: the VBS macro should store four values into four variables:
toField
, ccField
, subjectField
, and htmlBodyField
— these are the data needed for creating a new email.The problem is that I’m unable to pass these four variables from the VBS macro to AppleScript.
A. Here’s a command that works perfectly in the Mac terminal and passes the values to the "NewWinVBS.app" script, which successfully opens a new email with the provided values:
osascript /Applications/NewWinVBS.app "test@example.com" "cc@example.com" "Subject Example" "body of the email"
However, this command doesn’t want to run from the VBS macro at all! Here’s how I’m calling it from the macro:
' Prepare the command to run the AppleScript with parameters
command = "osascript /Applications/NewWinVBS.app " & _
Chr(34) & toField & Chr(34) & " " & _
Chr(34) & ccField & Chr(34) & " " & _
Chr(34) & subjectField & Chr(34) & " " & _
Chr(34) & htmlBodyField & Chr(34)
' Run the AppleScript application
Call Shell(command, vbNormalFocus)
B. The second command I tried is
open "/Applications/NewWinVBS.app"
This command does run from the VBS macro, and AppleScript successfully launches the NewWinVBS.app
. I’m calling it like this:
Dim command As String
command = "open " & Chr(34) & "/Applications/NewWinVBS.app" & Chr(34)
Call Shell("sh -c " & Chr(34) & command & Chr(34), vbNormalFocus)
But the issue here is that I can’t pass the variables from VBS using this method. Without passing variables, the command works, and it opens a new email window, but without the pre-filled data.
Does anyone experienced in AppleScript have any suggestions? Would appreciate any help!