How to set the out of office autoreply with applescript? - outlook

Trying to figure out how to use Applescript to toggle the Outlook autoreply option from off/on and vice versa.
I can query the status with
tell application "Microsoft Outlook"
query autoreply data exchange account 1
end tell
This works fine (although it returns the entire property list, and I only need the enabled element). The bigger problem is that I'm just not sure how to set the parameters with set autoreply data, as I'm not sure of the formatting of the command.
Appears in the dictionary as
set autoreply data v
set autoreply data exchange account
new data autoreply data
with the parameters of:
autoreply data n
properties
enabled (boolean) : Whether autoreplies are sent

I got this to work by getting the entire property list into a variable, toggling the enabled field, and then sending the property list back to Outlook.
tell application "Microsoft Outlook"
set theResult to query autoreply data exchange account 0
if enabled of theResult is false then
set enabled of theResult to true
else
set enabled of theResult to false
end if
set autoreply data exchange account 0 new data theResult
end tell

Related

Applescript Mail archive Actions

So, I finally got tired of manually sorting and archiving email on my Mac to get around some archaic mailbox size limits. I'm not a fan of the way Apple handles mail archiving, so I dug into a few examples that others had written to sort mail and slapped a short script together to filter through my email and archive everything older than 90 days. For the most part, easy stuff.
It is a tad annoying that Mail doesn't see "On My Mac" as a local account, so you need to adjust the code to blindly reference mailbox names.. but.. it works.
I think I'm just having an evaluation problem. I can sort the "Inbox" and archive mail from there quite easily.
on archive_email(target_account, target_mailbox, destination_account, destination_mailbox, oldemaildate)
tell application "Mail"
#Identify messages that need to be moved. If unread messages shouldn't be moved, change the end of the variable definition to read "is less than oldsentdate and read status is true)
set _msgs_to_capture to (every message of mailbox target_mailbox of account target_account whose date received is less than oldemaildate)
repeat with eachMessage in _msgs_to_capture
set archiveMailbox to (mailbox (destination_mailbox as string))
move eachMessage to archiveMailbox
end repeat
end archive_email
This doesn't work for the "Sent" folder, however. My guess is that the evaluation "whose date received is less than" is improper for the "sent" folder. Sadly, "whose date sent is..." doesn't seem to work either. I'm struggling to find the right variable and evaluation here.
The line bellow is perfectly working, assuming target_account and oldmaildate have correct values. To be sure, I replaced target_mailbox directly by "Sent Messages" :
set _msgs_to_capture to every message of mailbox "Sent Messages" of target_account whose date sent is less than oldemaildate
Please check values/types of your variables.
Also, I suggest you set the line below before the repeat loop and not inside, to increase speed :
set archiveMailbox to (mailbox (destination_mailbox as string))
You can do away with the repeat loop, which is inefficient, and achieve the move with a single command:
on archive_email(target_account as text, target_mailbox as text, ¬
destination_account as text, destination_mailbox as text, ¬
oldemaildate as date)
tell application "Mail" to ¬
move (every message ¬
of mailbox target_mailbox ¬
of account target_account ¬
whose date sent ¬
is less than oldemaildate) ¬
to mailbox destination_mailbox
end archive_email
Use date sent for Sent items, which I can confirm works.
System info: AppleScript version: "2.7", system version: "10.13.4"

Get e-mail address of selected mailboxes

I am trying to receive the mail addresse of the account that is active in mail.
So far I did the following
tell application "Mail"
set selected to selected mailboxes of message viewer 1
end tell
and
tell application "Mail"
email addresses of every account
end tell
But somehow i am not able do somethin like
tell application "Mail"
set selectedMailboxes to selection
set theAccount to account of selection
return theAccount
end tell
The Last applescript does not work. How can I retrieve the account of the mailbox in message vieview 1?
Try this
tell application "Mail"
try
set selectedMailbox to item 1 of (get selected mailboxes of message viewer 1)
set mailAddresses to email addresses of account of selectedMailbox
on error
display dialog "No Mailbox selected"
end try
end tell
As an account can have multiple mail addresses, the class of the variable mailAddresses is a list even there is only one address.
Get the address you want with an index number (1-based)
set myAddress to item 1 of mailAddresses
or
set myAddress to second item of mailAddresses

How to create list of Mail messages to move together rather than moving them individually?

I've managed to make this AppleScript work. It basically searches my inboxes for all my accounts and then selects any messages from specific address that are older than 14 days. It then proceeds to move each one of those filtered messages to a specified mailbox.
set ExcludeList to {"Trash", "Sent", "Drafts", "Deleted Messages", "Archive", "Junk", "Notes"} -- mailboxes you don't want to search
set SenderList to {"events#goldstar.com", "hello#touchofmodern.com", "staples#e.staples.com", "deals#livingsocial.com"} -- email addresses of senders you want to remove old emails for
set DestinationFolderName to "Old_Newsletters" -- mailbox to move messages to. If you want to just delete them, leave it blank.
set StaleTime to 14 -- days old the message must be before moved or deleted
set ShowMailboxesProgress to true -- determines if you want the "Processing" box displayed for each mailbox
set current_date to current date
set _msgs_to_move to {}
tell application "Mail"
set everyAccount to every account where enabled is true
-- Get acount-specific mailboxes
repeat with eachAccount in everyAccount
set accountName to the name of eachAccount
set currentMailbox to mailbox "INBOX" of eachAccount
set mailboxName to the name of currentMailbox
if mailboxName is not in ExcludeList then
if ShowMailboxesProgress then
display dialog "Processing folder " & mailboxName & " in account " & accountName
end if
try
repeat with SenderToRemove in SenderList
set messages_list to (every message of currentMailbox whose sender ends with "<" & SenderToRemove & ">")
repeat with i from 1 to number of items in messages_list
set theMessage to item i of messages_list
set difference to ((current_date) - (date sent of theMessage)) div days
if difference is greater than StaleTime then
if DestinationFolderName is not equal to "" then
move theMessage to mailbox DestinationFolderName of account "BlueStar Studios"
else
delete theMessage
end if
end if
end repeat
end repeat
end try
end if
end repeat
display dialog "Finished!"
end tell
It seems to work nice. HOWEVER, it takes a long time to run. Because it moves each filtered message individually. Is there a way to make a list of messages to be moved while in the repeat and then move that entire list of messages to another folder in one go?
Also, I'm running on 10.7.5 if that makes any difference.
Try using a filter reference form like this:
set d to (current date) - 14 * days
tell application "Mail"
repeat with a in (get accounts where enabled is true)
move (messages of mailbox "INBOX" of account a where date sent < d and (sender ends with "<events#goldstar.com>" or sender ends with "<hello#touchofmodern.com>")) to mailbox "Old_Newsletters" of account "BlueStar Studios"
end repeat
end tell

Set Messages (iChat) status to song currently playing in Rdio

I have the following script that successfully retrieves the current track and updates my Messages (iChat) status, but for this to work autonomously I guess I need to run it on a loop? Recommendations for that?
tell application "Rdio"
set theTrack to current track
set theArtist to artist of theTrack
set theName to name of theTrack
end tell
tell application "Messages"
if status is available then
set status message to ("♫ Playing in Rdio: " & (theArtist as string) & " - " & (theName as string))
end if
end tell
Unless Rdio has the ability to trigger scripts on certain condition (which you would have to check for yourself, as I am not a Rdio user myself – the rather sparse Rdio AppleScript docs on site do not indicate anything about that), your best chance to achieve this is to store your script as a Stay-Open AppleScript Application and put the script proper in the on idle handler. The AppleScript Language Guide has the nitty-gritty on this, if you want to look it up, but the basic procedure is:
wrap your script above in an on idle handler, i.e.:
on idle
tell application "Rdio"
set theTrack to current track
set theArtist to artist of theTrack
set theName to name of theTrack
end tell
tell application "Messages"
if status is available then
set status message to ("♫ Playing in Rdio: " & (theArtist as string) & " - " & (theName as string))
end if
end tell
return 0 -- change this to stray from the default 30 sec. interval
end idle
save the script as an AppleScript Application, making sure you check Stay open in the saving sheet.
Launch your newly created AppleScript app, and you are good to go – it will keep running, executing the idle handler periodically (every 30 seconds by default – you can change that value by returning an integer value from the idle handler, which will be evaluated as the number of seconds until the next check. If you want to be fancy, and the Rdio AS interface supports it, you could use the remaining playing time of your song, say…)

Applescript Moving Email to Trash, But Not Deleting from the Server

I wrote an AppleScript that moves selected emails to the Trash. The script works fine in that regard. The problem is that the emails remain on the server. Is there additional code I need to add to get it to do that? Here's the code:
using terms from application "Mail"
on perform mail action with messages these_messages for rule this_rule
tell application "Mail"
set the message_count to the count of these_messages
repeat with i from message_count to 1 by -1
set this_message to item i of these_messages
set this_content to (every character of content of this_message) as Unicode text
if "bowles" is not in this_content and "patton" is not in this_content then
set theAccount to account of mailbox of this_message
set mailbox of this_message to mailbox "Trash" of theAccount
end if
end repeat
end tell
end perform mail action with messages
end using terms from
It is hard to troubleshoot without seeing the entire script and the other rules that may be causing a problem. Try adding the Stop evaluating rules action to your rule :
using terms from application "Mail"
on perform mail action with messages these_messages for rule this_rule
tell application "Mail"
repeat with this_message in these_messages
set this_content to content of this_message
if "bowles" is not in this_content and "patton" is not in this_content then
set theAccount to account of mailbox of this_message
set junk mail status of this_message to false
set mailbox of this_message to mailbox "Trash" of theAccount
end if
end repeat
end tell
end perform mail action with messages
end using terms from
Sadly the answer appears to be to create a separate rule for email source. In the end, I just unsubscribed from the mailing lists as I hadn't seen any useful information from them in years.

Resources