Zooming the Inbox window in Mail

I work on a portable Mac. At my office it’s hooked up to a 19-inch widescreen display.

When I’m away from my office I used the built-in 14-inch display (not widescreen).

Every time I switch, my “Message Viewer” window in Mail is in the wrong place. So I thought I’d write a script to fix this.

tell application "System Events"
	tell process "Mail"
		click button 2 of window 1
	end tell
end tell

Which often works, but the problem is that the Message Viewer isn’t always the frontmost window.

So I tried this:

tell application "System Events"
		tell process "Mail"
			click button 2 of window "Inbox"
		end tell
end tell

But that doesn’t work because the name of the Message Viewer window isn’t static. When Mail first launches, it’s called “Inbox,” but then it quickly changes to something like “Inbox (295 messages, 4 unread).”

Still, the five leftmost characters are always “Inbox.”
(In theory, it might also be called “Sent” or “Drafts,” depending on how I left it; in practice 99% of the time it’s “Inbox.”

Is there any way to reference that window using a wildcard to match just part of the window name?
Is there an Applescript equivalent to “Inbox*”?

The ideal solution would be this:

tell application "System Events"
	tell process "Mail"
		
		(* First, make sure the Message Viewer window is frontmost *)
		tell menu bar 1
			click menu item "Message Viewer" of menu "Window"
		end tell
		
		(* Now that the Message Viewer window is frontmost, click the green Zoom button *)		
		click button 2 of window 1
	end tell
end tell

This would be even better, because it should work 100% of the time, even if I’d left the Message Viewer window showing Sent or Trash or whatever.

The problem is that the “click item” part of that script doesn’t work. I don’t get an error message, but the Message Viewer window doesn’t open. (Strangely, when I manually switch to Mail and click anywhere in the menu bar, I see the “Window” menu blink, and then the Message Viewer opens. So it’s kinda working, but not without manual intervention.)

If the Dock were scriptable, I could just tell the dock to click the mail icon, which always opens the Message Viewer window. But so far as I can tell, the Dock isn’t scriptable.

Any suggestions?

Model: iBook G4
AppleScript: AppleScript 1.10.7
Browser: Safari 522.12.1
Operating System: Mac OS X (10.4)

Hi,

why not simply set the bounds of the front window?
The window will be moved to the upper left corner, the size will be preserved

tell application "Mail"
	activate
	set {a, b, c, d} to bounds of window 1
	set bounds of window 1 to {0, 0, c - a, d - b}
end tell

Thanks, Stefan – I like that much better than clicking the “zoom” button.

But it still doesn’t solve the problem of making sure the Message Viewer window is in front.

If I have an open message window on top of the message viewer, then that’s the window that gets moved.

So how can I make sure that the Message Viewer window is the front-most window?

What’s about this


tell application "Mail"
	activate
	tell message viewer 1
		set {a, b, c, d} to bounds of its window
		set bounds of its window to {0, 0, c - a, d - b}
	end tell
end tell

Hurray! That’s exactly what I need.

It never occurred to me that Message Viewer was an object.

Thanks Stefan!

Read the dictionary!! :wink: