I am making my first attempt at scripting Mail.app. I am trying to toggle the visibility of the mailbox list on the left side of the mail viewer window. This looks like it should be possible by setting the ‘mailbox list visible’ property of the message viewer. However, I have tried two variants:
set vMsgViewer to make new message viewer
tell vMsgViewer
set mailbox list visible to false
end tell
set vMsgViewer to make new message viewer
set mailbox list visible of vMsgViewer to false
Both times I am given the following error:
On dismissing the error dialogue,
is selected in the code.
Am I doing something wrong, or is this a bug in Mail.app (v4.3)? Has anyone been able to set this property successfully?
Hi Jolin, since you liked the hack I posted in your other thread…
tell application "Mail"
activate
make new message viewer at front
end tell
tell application "System Events"
tell process "Mail"
click menu item "Hide Mailboxes" of menu 1 of menu bar item "View" of menu bar 1
end tell
end tell
-or-
tell application "Mail"
activate
make new message viewer at front
end tell
tell application "System Events"
tell process "Mail"
keystroke "m" using {command down, shift down}
end tell
end tell
Thanks so much, that helps a lot! I had actually tried something similar, but couldn’t get it to work (consistently) even when run from the script menu with Mail in the foreground:
tell application "System Events"
tell process "Mail"
click menu item 16 of menu 1 of menu bar item "View" of menu bar 1
end tell
end tell
It seems that the secret is first telling Mail to “activate”. So this does work (a variation on your script):
tell application "Mail" to activate
tell application "System Events"
tell process "Mail"
click menu item 16 of menu 1 of menu bar item "View" of menu bar 1
end tell
end tell
The above is essentially the same as your script using cmd-shift-m in that it toggles the mailbox visibility (because the wording of the menu item changes, your first script will hide but not show the mailboxes). But actually, for what I want to do, your script using “Hide Mailboxes” is better because I don’t want to toggle them, only hide them if they’re shown. This way I can use the following code to hide the mailboxes if they’re showing, but otherwise do nothing:
tell application "Mail" to activate
tell application "System Events"
tell process "Mail"
try
click menu item "Hide Mailboxes" of menu 1 of menu bar item "View" of menu bar 1
end try
end tell
end tell
Thanks again. This will make Mail much more useable for me!