applescript hide all but top window for Mail application?

Discussion in 'Mac Programming' started by ZestyOne, Dec 20, 2010.

  1. ZestyOne macrumors member


    Oct 18, 2009
    I'm trying to write an applescript that creates a new Mail message when i press command shift M.

    I have set up a new applescript service that creates new mail message. when it does this though, it starts both the inbox and then on top of that the new mail message (if i close mail inbox it works fine, but i also hide mail a lot and thats when it happens)

    due to my job i create a LOT of emails a day and ideally I'd like to have it show only the new mail window so that when i send it, i can go back to whatever I was doing before i started it. i am not good at applescript and i have tried googling for a few hours now to no avail... this is about the closest I got but it still is far from working. like is aid it wokrs fine if i close mail with command w but a lot of times i also use command H because its a hotkey on my house

    on run {input, parameters}
    	tell application "System Events"
    		tell process "Mail"
    			set focused of back window to true
    		end tell
    	end tell
    	tell application "System Events" to keystroke "w" using {command down}
    	return input
    end run
  2. andmr macrumors member

    Aug 25, 2008
    NE Florida
    You might try this:

    tell application "Mail"
    	close every window
    	set new_msg to make new outgoing message
    	set visible of new_msg to true
    end tell
    Good luck; hope this helps.

Share This Page