An applescript to automagically mark message as "junk"

Joined
Mar 2, 2007
Messages
250
Reaction score
18
Points
18
Location
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 Mail.app 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?

Thanks!
What I came up with:
Code:
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 Mail.app 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.
Top