Link to home
Start Free TrialLog in
Avatar of qeng
qeng

asked on

AppleScript to rename and save the attachments of emails in Oulook for Mac 2011

I have an email subfolder (ie a subfolder under Inbox) in Oulook for Mac 2011 which contains hundreds of emails each with an attachment.  

- the emails are all of identical structure (e.g. this email contains image 1 with attachment 'image1', this email contains image 2 with attachment 'image2', etc.)
- all emails have a single attachment
- some of the attachments have an identical filename but contain different information


I want to use an AppleScript to:

set a filenamePrefix
set a 'userdefinedCounter

open Microsoft Outlook
go to a specific email folder 'myFolder' (the subfolder is under On My Computer:Inbox:myFolder)
go to the bottom of the list of messages in that folder
open the bottom_most message

save the attachment in bottom_most message to myDesktopFolder while inserting the string 'filenamePrefix&userdefinedCounter' at the front of the attachment

move the bottom_most message from email folder myFolder to email folder myFolder2

increment userdefinedCounter

repeat this process for all emails in myFolder continuing to work from the bottom_most message upward

Note:  I don't know if it will be necessary to keep retargetting myFolder during the execution of this script in case a new email arrives causing Outlook to jump to the inbox mid-script (not sure if it does that)
Avatar of qeng
qeng

ASKER

I did spend hours looking for scriplets to pull together to accomplish this but was unsuccessful in finding anything that worked.

Before posting my question, I had gotten as far as Step 4:

Step1.  set a filenamePrefix (successful)
Step 2.  set a 'userdefinedCounter (successful)

Step 3.  open Microsoft Outlook (successful)
Step 4.  go to a specific email folder 'myFolder' (the subfolder is under On My Computer:Inbox:myFolder) (successful but will need to check in context of full script)
Step 5.  go to the bottom of the list of messages in that folder (don't know how to do)
Step 6.  open the bottom_most message (don't know how to do)

Step 7.  save the attachment in bottom_most message to myDesktopFolder while inserting the string 'filenamePrefix&userdefinedCounter' at the front of the attachment (don't know how to do)

Step 8.  move the bottom_most message from email folder myFolder to email folder myFolder2 (i know how to do)

increment userdefinedCounter (i know how to do)

repeat this process for all emails in myFolder continuing to work from the bottom_most message upward (I can likely get a loop working)
ASKER CERTIFIED SOLUTION
Avatar of Simon
Simon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of qeng

ASKER

Simon,

Brilliant.  It works.  I'm almost where I need to be.

The reason I wanted to start at the bottom of the list is because of the order the records are downloaded.  

For example, a user may elect to download records which are on successive pages 3 through 9.  Records of page 3 will arrive attached to the first email, records of page 4 will arrive next, etc..  On completion, the topmost message in the email folder will be for page 9 and the bottomost record  will be for page 3. The problem is that sometimes they arrive one after the other in emails (ie the time stamp is identical) with identical attachment names (e.g. "your records for today as of now") though the attachment content is different.

However, I can work around that problem (since I am concatenating all of the files anyhow; see below).  This was more of an interim measure so I'd know which page numbers had already been downloaded.

The last part I'm trying to achieve with this script is for it to concatenate the saved attachments residing in saveToFolder into one file (think of the attachments as txt files).

I can do this outside of the script using Terminal commands such as:

(after loading 'Terminal' from Applications)

CD \desktop
CD \myFolder
cat *.txt > filename.txt

It would be useful for 'filename' to be equal to 'prefix' set in line 2 of the script you kindly supplied.

How can we modify your script to execute the above Terminal commands (or equiv) once it has completed ?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of qeng

ASKER

Terrific.  Thx.  I adapted this to my needs.

Excellent help.  Thank you Simon.
Avatar of qeng

ASKER

Terrific help.  Thank you.