Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ZestyOne

macrumors regular
Original poster
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

Code:
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
 
You might try this:

Code:
tell application "Mail"
	activate
	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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.