Set Default Account in Entourage via Applescript

W

willmark

OK I have a fairly elaborate Apple script going for exporting emails
from Entourage to a specific hard coded folder on my hard drive.

The problem I am running into and cannot seem to solve is this: My
script can only select the default folders of "Folders on My
Computers" rather than the Exchange account that I have. All else in
the rest of the scipt which is now quite lengthy, works exactly the
way I want it to except this part. Can anyone shed light on what I am
doing wrong?

Disclaimer: I did not write all of this rather I gathered bits and
pieces and wrote the parts I needed to make it work for me.
Specifically Paul's advice in this thread has proven most valuable:

http://groups.google.com/group/micr...e+++Applescript&rnum=4&hl=en#c155a3ba685a1bf8

Here is the script thus far:
tell application "Microsoft Entourage"
activate
tell application "Microsoft Entourage"
set def to default mail account
if def = "Folders on My Computer" then
set account of window 1 to Exchange account "<User Name>"
end if
end tell
set mailFolders to {} as list
set mailFolders to Exchange account "<User Name>"
set thisFolder to choose from list mailFolders with prompt ¬
"Pick a mailbox to export" without multiple selections allowed

if ((count of messages of folder named thisFolder) = 0) then
display dialog "'" & (thisFolder as string) & ¬
"' contains no emails" buttons "OK" default button 1

Everything after the if ((count works fine. However when it runs the
script still selects the email in "Folders on My Computer" Rather then
the Exchange Account

TIA,

Mark
 
D

Diane Ross

OK I have a fairly elaborate Apple script going for exporting emails
from Entourage to a specific hard coded folder on my hard drive.

The problem I am running into and cannot seem to solve is this: My
script can only select the default folders of "Folders on My
Computers" rather than the Exchange account that I have. All else in
the rest of the scipt which is now quite lengthy, works exactly the
way I want it to except this part. Can anyone shed light on what I am
doing wrong?

Check out this script: AutoArchive Exchange Account to "On My Computer"

<http://www.entourage.mvps.org/exchange/autoarchive.html>
--
Diane Ross, Microsoft Mac MVP
Entourage Help Page
<http://www.entourage.mvps.org/>
One of the top five MS Entourage resources listed on the Entourage Blog.
<http://blogs.msdn.com/entourage/>
 
W

William Smith

Here is the script thus far:
tell application "Microsoft Entourage"
activate
tell application "Microsoft Entourage"
set def to default mail account
if def = "Folders on My Computer" then
set account of window 1 to Exchange account "<User Name>"
end if
end tell
set mailFolders to {} as list
set mailFolders to Exchange account "<User Name>"
set thisFolder to choose from list mailFolders with prompt ¬
"Pick a mailbox to export" without multiple selections allowed

if ((count of messages of folder named thisFolder) = 0) then
display dialog "'" & (thisFolder as string) & ¬
"' contains no emails" buttons "OK" default button 1

Everything after the if ((count works fine. However when it runs the
script still selects the email in "Folders on My Computer" Rather then
the Exchange Account

Hi Mark!

Part of your problem may be that you're confusing the "Folders on My
Computer" folder for an account. The default account will be the bold
account listed when you view Tools --> Accounts. That's not the same
thing as the "Folders on My Computer" folder. Therefore, your first "if"
statement will always be false and your "def" variable will be empty. In
fact, you don't really need to specify the default account. Just specify
the Exchange account by name.

To get you started experiment with this:

tell application "Microsoft Entourage"
set theAccount to Exchange account "<account name as it appears in
Accounts>"
set mailFolders to name of folders of theAccount as list
end tell

You can then get different pieces of information about the contents of a
folder in your Exchange account, such as:

subject of every message of folder "Inbox" of theAccount as list
sender of every message of folder "Inbox" of theAccount as list
category of every message of folder "Inbox" of theAccount as list

or just

every message of folder "Inbox" of theAccount as list

Hope this helps! bill
 
W

willmark

Hi Mark!

Part of your problem may be that you're confusing the "Folders on My
Computer" folder for an account. The default account will be the bold
account listed when you view Tools --> Accounts. That's not the same
thing as the "Folders on My Computer" folder. Therefore, your first "if"
statement will always be false and your "def" variable will be empty. In
fact, you don't really need to specify the default account. Just specify
the Exchange account by name.

To get you started experiment with this:

tell application "Microsoft Entourage"
set theAccount to Exchange account "<account name as it appears in
Accounts>"
set mailFolders to name of folders of theAccount as list
end tell

You can then get different pieces of information about the contents of a
folder in your Exchange account, such as:

subject of every message of folder "Inbox" of theAccount as list
sender of every message of folder "Inbox" of theAccount as list
category of every message of folder "Inbox" of theAccount as list

or just

every message of folder "Inbox" of theAccount as list

Hope this helps! bill

Thanks for the information, most helpful for pointing me in the right
direction.
 
W

willmark

Thanks for the information, most helpful for pointing me in the right
direction.

<BUMP!>

OK so after some tinkering here is what I came up with:

tell application "Microsoft Entourage"
activate
tell application "Microsoft Entourage"
set theAccount to Exchange account id 2
set InBoxFolder to theAccount
end tell
end tell
set docFolder to (path to documents folder from user domain)
set fpath to (choose folder default location docFolder with prompt ¬
¬
"Choose a folder in which to store your emails" without multiple
selections allowed) as string
--set fcount to 0
-- repeat with i in messages of folder named theAccount
set fcount to fcount + 1
set newFname to "" as string
set fname to (subject of i) as string
if ((count of characters of fname) > 30) then
set fname to ((characters 1 thru 25 of fname) & "...") as string
end if
if (fname contains ":") then
repeat with j in characters of fname
if (j as string = ":") then
set newFname to newFname & "-"
else
set newFname to newFname & j
end if
end repeat
set fname to newFname
end if

set fname to (fpath & fname) as string
tell application "Finder"
if (exists file (fname)) then
set k to 1
repeat while (exists file (fname & "-" & (k as string)))
set k to k + 1
end repeat
set fname to (fname & "-" & (k as string))
end if
end tell
save i in fname
tell application "Finder" to update file fname
tell application "Finder"
end tell


This part right here is perplexing me however:

set fcount to 0
repeat with i in messages of folder named theAccount

Every time I try to compile it is returns a syntax error of: "Expected
an end of line but found property or key form.

Again TIA
Mark
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top