An applescript to automagically mark message as "junk"

Mar 2, 2007
Reaction score
St Helens, OR, USA
Your Mac's Specs
MacBook CoreDuo 2Ghz 768M RAM
While trying to help someone over on another mac forum (because nobody else was offering anything useful to the topic originator) , I wrote my first useful Applescript (up until now, I'd modified existing scripts or done VERY basic things with it) and thought others here might find it of use.
What he was looking for:
"I have severals rules that detect Junk messages which are not caught by built-in Junk filter. My rules move this to the Junk folder. However, Mail doesn't mark them as Junk (obviously, since I haven't found a way to tell Mail -> "Mark this as Junk"). This means I have to go to my Junk mailbox, and manually mark all these messages as Junk.

Any ideas on how to avoid doing this manually and tell Mail to mark something as Junk?

What I came up with:
tell application "Mail" to activate
tell application "System Events"
	keystroke "j" using {command down, shift down}
end tell
After your 'junk' rule criteria are met, this script will automagically "press" command-shift j - the shortcut for selecting an item as junk mail.
Feel free to modify it, expand on it, etc.

Shop Amazon

Shop for your Apple, Mac, iPhone and other computer products on Amazon.
We are a participant in the Amazon Services LLC Associates Program, an affiliate program designed to provide a means for us to earn fees by linking to Amazon and affiliated sites.