Open Menu
Close Menu
Apple
Shopping Bag
Apple
Mac
iPad
iPhone
Watch
TV
Music
Support
Search apple.com
Shopping Bag
Lists
Open Menu
Close Menu
Terms and Conditions
Lists hosted on this site
Email the Postmaster
Tips for posting to public mailing lists
Mail Script to move "not junk" back to inbox
[
Date Prev
][
Date Next
][
Thread Prev
][
Thread Next
][
Date Index
][
Thread Index
]
Mail Script to move "not junk" back to inbox
Subject
:
Mail Script to move "not junk" back to inbox
From: Sean DeNigris <
email@hidden
>
Date: Sat, 2 Aug 2008 15:58:43 -0400
Hey, I got irritated that Mail doesn't return messages marked "not junk" back to the inbox, so I wrote a little script. Enjoy...
tell application "Mail"
local myInbox, myJunkMailbox, selectedMessages
set myInbox to mailbox "INBOX" of account "xxxxxxx"
set myJunkMailbox to mailbox "Junk" of account "xxxxxxx" of application "Mail"
set selectedMessages to selection as list
-- Do nothing if no message was selected
if selectedMessages is {} then return
-- Change the "junk" status of all selected messages and move them to inbox/junk as required
repeat with theMessage in selectedMessages
-- If We're marking as "Not Junk"
if junk mail status of theMessage is true then
-- Mark as "Not Junk"
set junk mail status of theMessage to false
-- Move the message to my inbox, if nec.
if mailbox of theMessage is not equal to myInbox then move theMessage to myInbox
else -- We're marking as "Junk"
-- Mark as "Not Junk"
set junk mail status of theMessage to true
-- Move the message to my junk mailbox, if nec.
if mailbox of theMessage is not equal to myJunkMailbox then move theMessage to myJunkMailbox
end if
end repeat
-- Get an adjacent message (that hasn't been deleted) to highlight after moving selected message
-- n.b. (Mail's idea's of after and before are backward)
--
-- Get the last selected message and create a variable to hold the message to select
local lastSelectedMessage, messageToSelect
set lastSelectedMessage to last item of selectedMessages
set messageToSelect to lastSelectedMessage
-- Keep getting next message until you find one that's not deleted
repeat
-- First try to get the following message
try
set messageToSelect to message before messageToSelect
-- If we have a message and it's not deleted, end loop
if deleted status of messageToSelect is not true then exit repeat
on error
-- If there was no next message, reset selection and end the loop
set messageToSelect to lastSelectedMessage
exit repeat
end try
end repeat
-- If we're still looking for a message to select, try searching up through the previous messages
if messageToSelect is lastSelectedMessage then
repeat
-- Try to get the previous message
try
set messageToSelect to message after messageToSelect
-- If we have a message and it's not deleted, end loop
if deleted status of messageToSelect is not true then exit repeat
on error
-- If there was no previous message, reset selection and end the loop
set messageToSelect to lastSelectedMessage
exit repeat
end try
end repeat
end if
-- If we found another message to select, select it now
if messageToSelect is not lastSelectedMessage then
set selected messages of message viewer 1 to {messageToSelect}
end if
end tell
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives:
http://lists.apple.com/archives/applescript-users
This email sent to email@hidden
Prev by Date:
Class ksty
Next by Date:
Re: Alias Files
Previous by thread:
Re: Class ksty
Next by thread:
Re: Rip Van Applescript
Index(es):
Date
Thread