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.
Model: iBook G4
AppleScript: AppleScript 1.10.7
Browser: Safari 522.12.1
Operating System: Mac OS X (10.4)