Re: Re1: Mail scripting : How to select… continuation...
Re: Re1: Mail scripting : How to select… continuation...
- Subject: Re: Re1: Mail scripting : How to select… continuation...
- From: awaw <email@hidden>
- Date: Mon, 19 May 2008 16:44:37 +0200
Thanks very much for your long post.
I'll study it at my time.
I've learned Applescript first with user's samples...
I try now, time to time, to optimize my code...
I've thinked to write a recursive subroutine for getting the
containers but I never succeed…
I've to study a little bit more!
Your sample come at a good time…
Regards
Gérard
Le 19 mai 08 à 15:28, Axel Luttgens a écrit :
On 12 mai 08, at 10:43, awaw wrote:
[...]
For my first experience with Applescript I have learned very much.
Damn! You really haven't chosen the easiest case... ;-)
On 13 mai 08, at 19:09, awaw wrote:
Below, my script.
I have higlighted the sequences for my question.
English comments in text clarify also the context.
[...]
On 13 mai 08, at 20:58, awaw wrote:
[...]
I'm hoping now to be able to simplify my code...
Your script made me really think as it involves numerous aspects of
Mail's scripting model, which sometimes appears a bit anarchistic.
You sure managed to get a working version of your script; I'm
posting mine anyway, should it provide you with some ideas for other
tasks with Mail.
Have a nice day,
Axel
-- No optimization here: just a systematization attempt.
property Pause : 0.1
-- That handler's name should tell everything...
on WalkMBox(MBox)
local SubMBox
tell application "Mail"
set selected mailboxes of first message viewer to {MBox}
delay my Pause
repeat with SubMBox in mailboxes of MBox
my WalkMBox(SubMBox)
end repeat
end tell
end WalkMBox
-- Returns a list of items in ToFilter but not in ToRemove.
on FilterList(ToFilter, ToRemove)
local Filtered, Itm
set Filtered to {}
repeat with Itm in ToFilter
if {contents of Itm} is not in ToRemove then copy contents of Itm
to the end of Filtered
end repeat
return Filtered
end FilterList
-- Various handlers allowing to build sets of mailboxes that may be
used to build other sets.
-- Most of them are "naturally" built and sorted by Mail's rules.
-- The top-level mailboxes provided by properties of Mail; they are
more containers for other
-- mailboxes than real mailboxes.
on PropertiesTLMBoxes()
tell application "Mail" to return {inbox, outbox, drafts mailbox,
sent mailbox, trash mailbox, junk mailbox}
end PropertiesTLMBoxes
-- All the "real" mailboxes accessed through properties of Mail.
on PropertiesMBoxes()
local MBoxes, TLMBox
tell application "Mail"
set MBoxes to {}
repeat with TLMBox in my PropertiesTLMBoxes()
set MBoxes to MBoxes & mailboxes of TLMBox
end repeat
return MBoxes
end tell
end PropertiesMBoxes
-- The top-level mailboxes available as elements of Mail.
on LocalTLMBoxes()
tell application "Mail" to return mailboxes whose name of its
container is missing value
end LocalTLMBoxes
-- The top-level mailboxes available as elements of accounts.
on AccountsTLMBoxes()
local TLMBoxes, Acct
tell application "Mail"
set TLMBoxes to {}
repeat with Acct in accounts
set TLMBoxes to TLMBoxes & (mailboxes of Acct whose name of its
container is missing value)
end repeat
return TLMBoxes
end tell
end AccountsTLMBoxes
-- This is one out of two cases needing to refer mailboxes by name;
I'm relying on what
-- seems to be default names. If, for some reason, Mail had to make
use of other names,
-- one should find a way to answer questions such as "which
mailboxes are used for
-- storing notes?"; I fear there would no way other than parsing
com.apple.mail.plist...
on NotesMBoxes()
tell application "Mail" to if exists mailbox "Notes" then return
{mailbox "Notes"}
return {}
end NotesMBoxes
-- This is the second case needing named mailboxes.
on TodosMBoxes()
local MBoxes, Acct
tell application "Mail"
set MBoxes to {}
if mailbox "ToDos" exists then copy mailbox "ToDos" to the end of
MBoxes
repeat with Acct in accounts
if mailbox "Apple Mail To Do" of Acct exists then copy mailbox
"Apple Mail To Do" of Acct to the end of MBoxes
end repeat
return MBoxes
end tell
end TodosMBoxes
-- OK, let's walk the sidebar...
tell application "Mail"
-- Section: MAILBOXES
-- This may have the side effect to reveal Outbox when there is no
pending message.
-- As well as to reveal Junk, even if the prefs tell to keep junk
mail in inbox.
repeat with MBox in my PropertiesTLMBoxes()
my WalkMBox(MBox)
end repeat
-- Section: REMINDERS
-- Subsection "Notes"
-- Most GUI elements here are not selectable through AS, and even
don't seem to
-- display "true" mailboxes (kind of smart mailboxes instead).
repeat with MBox in my NotesMBoxes()
my WalkMBox(MBox)
end repeat
-- Subsection "To Do"
-- A strange mix of GUI artifacts (such as the "To Do" heading),
"true" mailboxes
-- and calendars.
repeat with MBox in my TodosMBoxes()
my WalkMBox(MBox)
end repeat
-- Section: SMART MAILBOXES
-- No relationship with "true" mailboxes, and nothing in the AS
model.
-- Section: ON MY MAC
-- All local mailboxes not appearing in other sections (i.e. not
handled by Mail itself).
repeat with MBox in my FilterList(my LocalTLMBoxes(), my
PropertiesMBoxes() & my NotesMBoxes() & my TodosMBoxes())
my WalkMBox(MBox)
end repeat
-- Section: BY ACCOUNT SPECIFIC MAILBOXES
-- All account-related mailboxes not appearing in other sections
(i.e. mailboxes on
-- imap servers and not handled by Mail itself).
repeat with MBox in my FilterList(my AccountsTLMBoxes(), my
PropertiesMBoxes() & my NotesMBoxes() & my TodosMBoxes())
my WalkMBox(MBox)
end repeat
end tell
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (applescript-
email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden