MS Outlook script runs, but no messages move - outlook

I'm trying to write an applescript that I can automate to clean up my mailbox on a schedule. Here is the code:
tell application "Microsoft Outlook"
set srcFolder to mail folder "Inbox" of on my computer
set destFolder to mail folder "Deleted Items" of on my computer
set selectedMessages to messages of srcFolder
repeat with theMessages in selectedMessages
if (sender of theMessages is "null#null.com") then
move theMessages to destFolder
end if
end repeat
end tell
The code is going to search for the email address, then move those messages to the Deleted Items folder.
The script runs, but no messages run. Can anyone see why this wouldn't run correctly?

Have you tried deleting both occurrences of
of on my computer
It may not be necessary, and might be messing up the script.
You might also try changing this line:
set selectedMessages to messages of srcFolder
to
set selectedMessages to every message of srcFolder
I do not have Outlook on my machine, so I cannot test these.

Related

Applescript intermittently fails when moving selected email messages to folder

hope someone can tell me what I am doing wrong. I am an applescript newby, with help from other posts was able to use automator, applescript & keyboard shortcut to move selected messages to an outlook folder. Worked great. I transferred to another mac, works fine there. Then intermittently I get an error message on both macs:
The action "Run Applescript" encountered an error: "No messages selected. Select at least one message."1
I initially thought it was related to when I last opened up Outlook as it seemed to fix itself after a few minutes. Then problem comes back, no rhyme or reason I can perceive. Yes, I do in fact select a message first.
I made two copies of script, differences are folder names. Two different hotkeys attached, option+B for one folder option+P for another. Same error if I use hotkey or go to outlook/services then select the script
Any clue what I am doing wrong? thanks in advance for any insight!
Outlook for mac / O365 v: 16.62 (22061100)
osx big sur v: 11.6 (20G165)
here is script:
on run {input, parameters}
tell application "Microsoft Outlook"
activate
set msgSet to current messages
if msgSet = {} then
error "No messages selected. Select at least one message."
error -128
end if
set theMsg to item 1 of msgSet
set theAccount to account of theMsg
set archiveFolder to folder "Broker Correspondence" of theAccount
repeat with aMessage in msgSet
move aMessage to archiveFolder
end repeat
end tell
return input
end run

Outlook 2016 Mac: Move message to a folder in Gmail Account via AppleScript

I have an AppleScript to archive a message in Outlook 2016 for Mac. Please see below. On Outlook 2016 for Mac 16.13 (released in May 2018 via Insider Slow channel), the script fails for messages in newly added Gmail accounts when it tries to get the account of the selected message/folder (curAccount is missing value after set curAccount to account of curFolder).
This version of Outlook added support Google Calendars and Contacts and you need to remove and add Gmail account in order to get this feature. The script works fine for Exchange/Office365 accounts as well as for Gmail accounts added before the upgrade to 16.13. It fails only for newly added Gmail accounts. I guess, the Gmail integration is done differently now in this new release of Outlook 2016 for Mac.
Do you know a work-around for this issue? Do you have a script example to get a folder handle in Gmail account?
AppleScript
tell application "Microsoft Outlook"
set currMsgs to current messages
-- Check to make sure items are selected, if not then quit
if (count of currMsgs) is 0 then
display notification "No message selected" with title "Microsoft Outlook" subtitle "Move to Archive"
return
end if
-- Iterate through selected items
repeat with msg in currMsgs
set curFolder to folder of msg
set curAccount to account of curFolder
if curAccount is missing value then
display dialog ("An error occurred and the messages were not moved " & name of curFolder & " . Done") buttons {"Quit Script"} default button 1 with icon stop
return
end if
set destFolder to folder "Archived" of curAccount
move msg to destFolder
end repeat
-- 1 Notification...
if (count of currMsgs) is 1 then
display notification "One message moved to " & name of curAccount & ":" & name of destFolder with title "Microsoft Outlook" subtitle "Move to Archive"
end if
-- Multi Notification...
if (count of currMsgs) > 1 then
display notification "" & (count of currMsgs) & " messages moved to " & name of destFolder with title "Microsoft Outlook" subtitle "Move to Archive"
end if
end tell
I received a negative response from Outlook for Mac support. Here it is. Hope it helps someone looking for an answer.
Note: This is not an answer to the question. I should have added it as a comment to the question above, but the size of text below was more than what was allowed in a comment.
Hello, I'm one of the Outlook Escalation Engineers. I understand you
would like to verify and see a documentation regarding Apple Script
Automation with Google Preview accounts.
I confirm Google Preview has no way to automate in Apple Script. At
the moment, we have no documentation available in public regarding
this. I will check what we can do about it and I will let you know. :)
I did an extra mile to submit a feature request about this through
the link below. Please vote for it once it is approved and available.
Title: Give a way for Google Preview accounts to automate in Apple
Script
https://outlook.uservoice.com/forums/293343-outlook-for-mac/suggestions/34408744-give-way-for-google-preview-accounts-to-automate-i
I apologize for the inconvenience but we appreciate your patience and
understanding.

Using an applescript/automator to attach multiple items to a new Outlook message

I've worked out (found online) how to attach a single item from Finder to a new Outlook message. I've played with this format a good amount - changed 'selecteditem' and selection and some other more major changes - but I can't work out how to get more than one item to attach to a new outlook message at a time.
Only a single item attaches to each new outlook message. There are no Outlook Automator options in Automator - I think Office 365 did away with them.
My current script is as follows:
tell application "Finder" to set selectedItem to item 1 of (get selection)
set theAttachment to selectedItem as alias
set fileName to name of selectedItem
tell application "Microsoft Outlook"
set newMessage to make new outgoing message with properties {subject:fileName}
tell newMessage
make new attachment with properties {file:theAttachment}
end tell
open newMessage
get newMessage
end tell
I'm currently trying use this script in Automator as a service so I have a right click option to send files directly to a new Outlook message. It's currently setup like this.
Your Automator Service gets "Files or Folders" from Finder. This part is OK. Just the content of the applescript must be changed.
To read these inputs (the selected files from Finder), you must use the "on run" handler where "input" will be the selected files.
The script bellow must replace your current script. I assumed that the subject of your email should be the name of the first selected file in case of multiple selection:
on run {input, parameters}
set SelectedItems to input
tell application "Finder" to set fileName to name of first item of SelectedItems
tell application "Microsoft Outlook"
set newMessage to make new outgoing message with properties {subject:fileName}
tell newMessage
repeat with aFile in SelectedItems -- the loop through all selected items
make new attachment with properties {file:aFile}
end repeat
end tell
open newMessage
get newMessage
end tell
return input
end run
On top of that, I have 2 comments :
1) this script does not filter the case when you select a folder. Inside the loop, you may want to add a "if" test to check file or folder and take action in case selection is a folder.
2) I do not understand the overall process you want to perform: Select files, go to menu Service to run this service, which creates a new Outlook message with these files as attachment...You can do all this by just selecting the files and drag/drop them on the Outlook icon in the dock. it will immediately create a new blank message with all the attached files.
Old question, but I ran into this today and used the "Shortcuts" app on MacOS to get this working, or at least something similar.
Start to finish:
Opened Shortcuts app on MacOS (Monterey)
Select (+) to create new shortcut
Searched for and select "Run AppleScript"
Highlight Text in script and replace with below:
on run {input, parameters}
set SelectedItems to input
tell application "Finder" to set fileName to name of first item of SelectedItems
tell application "Microsoft Outlook"
set newMessage to make new outgoing message with properties {subject:fileName}
tell newMessage
repeat with aFile in SelectedItems -- the loop through all selected items
make new attachment with properties {file:aFile}
end repeat
end tell
open newMessage
get newMessage
end tell
return input
end run
On the top right of the Shortcuts window select the Shortcut Details (Adjustable Bars Icon)
Select "Pin in Menu Bar", "Use as Quick Action", "Finder" & "Services Menu".
Under the "Run AppleScript with" select "Shortcut Input".
It should look like this:
And this is how you use it within the Finder:
If outlook is open, it will attach it like shown:

Applescript for Outlook 2011 to iterate through all folders such as inbox etc

I want to loop throgh all the folders of outlook 2011 in MAC computer using Apple script (means just sort of automation).
i have script which throws error while running.
tell application "Microsoft Outlook"
set thisAccount to exchange account "Sigmaco"
set thisFolders to mail folder of thisAccount
end tell
*tell application "Microsoft Outlook" to set folderList to the folders*
repeat with nextFolder in folderList
my ProcessFolder(nextFolder, outputFolder)
end repeat
but the line in bold style throws error that it cannot iterate through all folders.
please help...
because accounts can have the same name (assuming) you have to specify first one then drill down like this
tell application "Microsoft Outlook"
repeat with afolder in (mail folders of (first exchange account whose name is "Sigmaco"))
log (get name of afolder)
end repeat
end tell
if you want to iterate through all folders of all accounts you can skip a bit of the drilling
tell application "Microsoft Outlook"
repeat with afolder in mail folders
-- do stuff
end repeat
end tell

Applescript for Outlook 2011 that moves all messages from a specific folder that match a source account to a different folder

As the Title states "Help with an Applescript for Outlook 2011 that moves all messages from a specific folder that match a source account to a different folder."
So, I have a "rule" that moves all new mail on my exchange account into a "Inbox" in a subfolder On My Computer. When I delete items form this subfolder inbox it goes into the "Deleted Items" On My Computer. I have made a sub-folder for "Deleted Items" in the same place as my "Inbox" sub-folder and I would like to run an Applescript on a schedule that can go into the main Deleted Items On My Computer and find the messages from that exchange account and move them into "subfolder/Deleted Items".
Googling about I cobbled the below together which will move ALL mail in Deleted Items:
tell application "Microsoft Outlook"
set topFolder to mail folder "AT&T" of on my computer
set destFolder to folder "Deleted Items" of topFolder
move every message of mail folder "Deleted Items" of on my computer to destFolder
end tell
The part I can't get past is now only selectively moving mail whose "account" is a specific value, like thus:
tell application "Microsoft Outlook"
set topFolder to mail folder "AT&T" of on my computer
set destFolder to folder "Deleted Items" of topFolder
move (every message of mail folder "Deleted Items" of on my computer whose account = "Att") to destFolder
end tell
the last addition of trying to filter by account kicks up the error
Microsoft Outlook got an error: Can’t make account into type specifier.
Any help appreciated!!
Devised a solution that works. Instead of a single line, selected all messages in the folder and looped through them, grabbing the account name as text and doing the compare and move.
tell application "Microsoft Outlook"
set topFolder to mail folder "AT&T" of on my computer
set destFolder to folder "Deleted Items" of topFolder
set srcFolder to mail folder "Deleted Items" of on my computer
set selectedMessages to messages of srcFolder
repeat with theMessages in selectedMessages
set thisAccount to account of theMessages
if (name of thisAccount as text is "Att") then
if (is read of theMessages is false) then
set theMessages's is read to true
end if
move theMessages to destFolder
end if
end repeat
end tell

Resources