Re: Organizing mail into mail folders with Applescript?
Re: Organizing mail into mail folders with Applescript?
- Subject: Re: Organizing mail into mail folders with Applescript?
- From: Axel Luttgens <email@hidden>
- Date: Mon, 1 Feb 2010 13:40:34 +0100
Le 1 févr. 2010 à 00:52:03, Konrad Michels a écrit :
> Hey
> Apologies for taking so long to get back to the conversation. What I've been up to is refining the original script I had to at very least first mark all the messages as read in the folders I wanted. The additional challenge was that it was not all the sub-folders that I wanted touched, just some of them. You are correct about the {"name", "othername"} format not working. Not entirely sure why at this point, but I got myself a new Applescript book today so hopefully at some point I'l work it out.
Hello Konrad,
As far as the language itself is concerned, it never hurts to have the ASLG at hand as well:
http://developer.apple.com/mac/library/documentation/AppleScript/Conceptual/AppleScriptLangGuide/AppleScriptLanguageGuide.pdf
Now, this is only part of the story.
Each scriptable application comes with its model, i.e. the way it exposes and organizes its features, and the extent to which it implements the languages features. For example, some applications don't implement AppleScript's filter reference forms (the "whose" clauses), while other do, but possibly in limited cases only.
The ultimate documentation for an application is its dictionary and, well, trial and error.
> So what I have so far to loop through the folders and mark the messages as read is:
>
> tell application "Mail"
> tell (mailboxes whose name is "svn" or name is "hyperpush" or name is "opsnotify" or name is "chronicle" or name is "linx announcements" or name is "Atlas" or name is "e-social") of mailbox "Inbox" of account "work account"
> set read status of (every message whose read status is false) to true
> -- set the mailbox of every message to (mailbox "201001" of mailbox "2010" of mailbox "work archive")
> end tell
> end tell
>
> This works just as well as my original script but is a lot more compact. Pity the list feature isn't working or it could be even *more* compact.
>
> I've got your other mail about the actual move part and will see how I go about getting that working. The challenge that I've not been able to master yet is of adressing a local mailbox, since it has no account property associated with it.
When looking at the application entry in Mail's dictionary, you'll notice there are some properties related to the mailboxes that Mail manages itself, in a systematic way: inbox, sent mailbox, trash mailbox, drafts mailbox...
In this precise case, you are interested in the inbox property; to get an idea of how things are organized by Mail in its AppleScripting model, you may want to run this one:
tell application "Mail"
mailboxes of inbox
end tell
and have a look at the log.
On the other hand, you'll notice that the dictionary also shows that the application has "mailboxes" as elements. Thru an experiment similar to the above one:
tell application "Mail"
mailboxes
end tell
it appears that the local mailboxes created by the user are such application elements and that, quite logically, they are not account-related.
As a result,
tell application "Mail" to get mailbox "INBOX" of account "work account"
asks Mail to access one of those top-level mailboxes that may also be reached thru the inbox property; on the other hand,
tell application "Mail" to get mailbox "INBOX"
would ask Mail to refer a local mailbox named "INBOX", that could also be accessed as the nth item of mailboxes, for some value of n and provided that the local mailbox exists.
Now, let's suppose local mailbox "INBOX" exists and has a sub-mailbox named "sample".
It could be addressed in a hierarchical way:
mailbox "sample" of mailbox "INBOX"
as well as in a path-like way:
mailbox "INBOX/sample"
But for scripting the *creation* of sub-mailboxes, it seems that the latter is mandatory.
> Your script you sent in the other mail looks really interesting and I will try it and see how it works!
Hoping it will be of some help. ;-)
Axel _______________________________________________
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