• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Scripting Mailbox Properties in Mail
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Scripting Mailbox Properties in Mail


  • Subject: Re: Scripting Mailbox Properties in Mail
  • From: Axel Luttgens <email@hidden>
  • Date: Fri, 04 Jan 2008 11:13:23 +0100

On 3/01/08 23:31, Hylton Boothroyd wrote:

[Mail 2.1.2, Script Editor 2.1.1, OS 10.4.11 on Intel MacMini with 2Gb memory]

I'm trying to repair a deficiency in the behaviour of Apple's Mail.app: it loses my selected View > Columns > Mailbox modification of settings every time I leave and return to my "Unread" smart mailbox. So what I ultimately want is something that corrects the selection on access -- I'm assuming there isn't a non-scripting solution to cure the problem once and for all.

I can't tell from my first experiments
whether what I am trying is in principle do-able,
whether I just need a bit of help in getting the right way of saying things,
whether a smart mailbox poses any additional scripting difficulties.


My first exploratory attempt

====
tell application "Mail"
set mailboxName to "Unread"
try
set (mailbox column of visible columns of mailboxName) to true
on error the error_message number the error_number
[a standard error handler from Script Editor's contextual menu]
end try
end tell
====

reports
"Error: -10006. Can't set «class mvvc» of \"Unread\" to true."

It also reports the same error
for "Humble" which doesn't exist
for "Buying" which exists as a simple top-level mailbox.

Which doesn't narrow things down much!



That's because the error goes about trying to incorrectly set a string property; no mailbox is involved here.



So I would be grateful for any pointers at any level: Matt Neuburg's wonderful chapter on Dictionaries makes me think I won't make it on my own!

This is my first go at scripting in OS X, though I did plenty of simple personal scripts and adaptations in OS 9.


Searching Mail's dictionary, it appears that "visible columns" is a message viewer's property:

message viewer n [inh. item] : Represents the object responsible for
managing a viewer window

elements
contains messages; contained by application.

properties
[...]
visible columns (attachments column/buddy availability
column/message color/date received column/date sent
column/flags column/from column/mailbox column/message
status column/number column/size column/subject
column/to column) : List of columns that are visible.
The subject column and the message status column will
always be visible
[...]

Moreover, that property is said to contain a list of columns.

So, let's have a look at how this works from a practical point of view:

tell application "Mail" to get visible columns of first
message viewer
--> {message status column, buddy availability column, subject
column, from column, to column, date received column}

Clearly, one has to target a message viewer (not a mailbox) and to enumerate the columns to be made visible (not to set boolean values).

So, for example, something like this should work:

tell application "Mail"
tell first message viewer
if mailbox column is not in visible columns then set visible columns to visible columns & mailbox column
end tell
end tell


That is, one concatenates the column whose visibility is wanted to the existing list of visible columns.

With some more experiments, it appears that the existence test is not needed: Mail will perform housekeeping as needed (remove any duplicate); so, the above may be simplified as:

tell application "Mail"
tell first message viewer
set visible columns to visible columns & mailbox column
end tell
end tell

HTH,
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
References: 
 >Scripting Mailbox Properties in Mail (From: Hylton Boothroyd <email@hidden>)

  • Prev by Date: Import Playlist to iTunes
  • Next by Date: Adding Overlay Text to a JPEG
  • Previous by thread: Scripting Mailbox Properties in Mail
  • Next by thread: Re: Scripting Mailbox Properties in Mail
  • Index(es):
    • Date
    • Thread