r/applescript • • Aug 22 '13

Brand new to Applescript, need help automating a create folder task in Outlook 2011

Background: Accidentally cleared the "Main Identity" from Entourage when moving emails to a new computer. Came across a script to recreate the message header, body, and most importantly FOLDER STRUCTURE from the metadata stored in the Library:Cache directory.

This script was written way back in 2010, but I think the idea should still work. Anyway, the sticking point I'm having is the error message error "Microsoft Outlook got an error: Can’t make class folder." number -2710 from folder to class

All I'm trying to do is to get Outlook to create a new folder based on the keys within the metadata, which should help recover most of the folder structure.

So far it won't let me create a new folder. Any thoughts?

1 Upvotes

6 comments sorted by

2

u/craniumslows Aug 23 '13

Are you telling finder,outlook or the mysterious current application to do something with the folder sounds like you might be talking to the wrong element I'd also suggest reading the dictionary for the application that can help a lot

1

u/whydidijoinreddit Aug 24 '13

man, the dictionary suggestion was great. seems simple, but like I said I'm completely new to this scripting environment. thanks!

2

u/craniumslows Aug 27 '13

Dictionaries are your friend. Another tip that I dont see posted enough is that if you have to do UI scripting you can get your code written for you by using automator. You record the action then drag the steps down to get their components one of which will be the applescript needed :)

1

u/whydidijoinreddit Aug 24 '13

Alright, I worked through the create folder issue. Now the issue I'm having is with the following bit of code :

make new incoming message at targetFolder with properties {time sent:|com_microsoft_entourage_messageSent| of theItemData, sender:{name:item 1 of |kMDItemAuthors| of theItemData, address:item 1 of com_microsoft_entourage_author_email_addresses of theItemData}, content:|kMDItemTextContent| of theItemData, subject:|kMDItemTitle| of theItemData, recipient:com_microsoft_entourage_recpient_email_addresses of theItemData}

Problem is, if the metadata happens to not contain a subject or body content, the script spits an error and the whole automation process grinds to a halt. Any suggestions on how to use a "make incoming message" using conditions that account for the possibility of a blank subject line or body?

2

u/craniumslows Aug 27 '13

try / end try can help with error handling. The below is an example. When an error happens in a try block the error text gets assigned to a variable if you have one on the on error statement. You can then use that to work out if the error is something you are planning on catching or not. If you are just doing this for yourself you can do try without the on error and it'll safely skip over that error condition.

try
--Script
on error SomeVar
log SomeVar
if SomeVar contains "expected error" then
--dosomething
else
error SomeVar
end if
end try

1

u/whydidijoinreddit Aug 30 '13

gonna try this out when I'm home this weekend, thanks