• 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
Re: Applescript counting mails keeps counting mail in other folders
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Applescript counting mails keeps counting mail in other folders


  • Subject: Re: Applescript counting mails keeps counting mail in other folders
  • From: Brian Christmas <email@hidden>
  • Date: Wed, 27 May 2015 12:57:20 +1000

G’day Fred

This question has plagued me for 10 years.

The only way of reliably resetting a mailbox is to quit Mail, and re-start it.

My method is…

1. Create two new mailboxes ‘items to shift’ & ‘items to store’.

2. Create a mail rule that shifts All incoming mail from your inbox to ‘items to shift’.

3. when your script/App starts, move the mail from ‘items to shift’ to ‘items to store’

4. Count the items in ‘items to store’.

5. Deal with the FIRST item (oldest) in 'items to store', and move it.

6. In a timed loop, count the items in ‘items to store’.

7. If the count decreases by one before the looping ends, deal with the next item.

8. If the loop times out without a decrease, quit Mail, and restart it.

9. While quitting Mail, check that it’s actually quit before restarting, or issue a force quit.

10. When the count of ‘items to store’ reaches 0, check for and move any mail from ‘items to shift’ again.

Here’s some handlers you might find useful.

Regards

Santa

on mailRuleCreator:sender
# say 503
set isThisStartUp to false #forces reset of rule every time this is run
tell application "Mail"
activate
try
tell current application to delay 0.2
tell application "System Events" to tell process "Mail"
click menu item "Message Viewer" of menu 1 of menu bar item "Window" of menu bar 1
end tell
if not (exists mailbox "* items to shift") then make new mailbox with properties {name:"* items to shift"}
set theAddRuleMailbox to false
if not (exists rule "Move to '* items to shift'") or not isThisStartUp then
set inBoxList to name of every account whose enabled is true as list
if (count of inBoxList) = 1 then
set theAddRuleMailbox to item 1 of inBoxList
else
set theAddRuleMailbox to choose from list inBoxList with prompt "Please choose an Account to which to add the Mail rule " & return & return & "\"Move to '* items to shift'\"." & return with title "Mail Manager add Mail rule" OK button name "Choose this Inbox Account" cancel button name "I'll set the rule myself"
end if
end if
if theAddRuleMailbox ≠ false then
try
delete (every rule where name contains "items to shift")
end try
try
delete (every rule where name contains "Autom")
end try
if not (exists rule "Move to '* items to shift'") then
tell application "System Events" to tell process "Mail"
try
keystroke return
end try
click menu item "Preferences…" of menu 1 of menu bar item "Mail" of menu bar 1
tell current application to delay 0.1
click button 8 of toolbar 1 of window 1
# 
# Set descriptive name of rule
#
click button "Add Rule" of group 1 of group 1 of window "Rules"
set value of text field 1 of sheet 1 of window "Rules" to "Move to '* items to shift'"
#
# First, select the 'all' menu item
#
click pop up button 1 of sheet 1 of window "Rules"
click menu item "all" of menu 1 of pop up button 1 of sheet 1 of window "Rules"
# 
# Set first scroll area, 'Conditions'
#
click pop up button 1 of scroll area 1 of sheet 1 of window "Rules"
# The darn popups change numbers whilst 'Account' is being selected
try
click menu item "Account" of menu 1 of pop up button 1 of scroll area 1 of sheet 1 of window "Rules"
tell current application to delay 0.1
end try
# so we have to try both 1 & 2 popups
try
click menu item "Account" of menu 1 of pop up button 2 of scroll area 1 of sheet 1 of window "Rules"
tell current application to delay 0.1
end try
click pop up button 1 of scroll area 1 of sheet 1 of window "Rules"
tell current application to delay 0.1
click menu item (theAddRuleMailbox as text) of menu 1 of pop up button 1 of scroll area 1 of sheet 1 of window "Rules"
tell current application to delay 0.1
#
click button "add criterion" of scroll area 1 of sheet 1 of window "Rules"
#
click pop up button 3 of scroll area 1 of sheet 1 of window "Rules"
click menu item "Every Message" of menu 1 of pop up button 3 of scroll area 1 of sheet 1 of window "Rules"
tell current application to delay 0.1
# 
# Set second scroll area, 'Actions'
#
click pop up button 1 of scroll area 2 of sheet 1 of window "Rules"
tell current application to delay 0.1
click menu item "Move Message" of menu 1 of pop up button 1 of scroll area 2 of sheet 1 of window "Rules"
tell current application to delay 0.1
click pop up button 2 of scroll area 2 of sheet 1 of window "Rules"
tell current application to delay 0.1
click menu item "* items to shift" of menu 1 of pop up button 2 of scroll area 2 of sheet 1 of window "Rules"
tell current application to delay 0.1
#
click button "add action" of scroll area 2 of sheet 1 of window "Rules"
tell current application to delay 0.1
#
click pop up button 3 of scroll area 2 of sheet 1 of window "Rules"
tell current application to delay 0.1
click menu item "Run Applescript" of menu 1 of pop up button 3 of scroll area 2 of sheet 1 of window "Rules"
tell current application to delay 0.1
click pop up button 4 of scroll area 2 of sheet 1 of window "Rules"
tell current application to delay 0.1
try
click menu item "Mail Manager Caller" of menu 1 of pop up button 4 of scroll area 2 of sheet 1 of window "Rules"
on error
try
click menu item 1 of menu 1 of pop up button 4 of scroll area 2 of sheet 1 of window "Rules"
end try
end try
tell current application to delay 0.1
click button "OK" of sheet 1 of window "Rules"
tell current application to delay 0.1
try
keystroke return
end try
tell current application to delay 0.1
try
click button 1 of window 1
end try
end tell
end if
end if
on error errmsg number errNum
tell application "System Events" to tell process "Mail"
try
tell current application to delay 0.1
click button "OK" of sheet 1 of window "Rules"
end try
try
click button 1 of window 1
end try
end tell
display dialog "mailRuleCreator error " & errmsg
end try
end tell
end mailRuleCreator:


To force Quit


on MM_Quitter()
  if my voiceSetter as text is "Use voice 'Vicki'" then
say ("Mail Manager is turning off") using my TheVoice
else
say ("Mail Manager is turning off")
end if
  set The_app to "Mail Manager"
try
tell application "Finder"
tell application "System Events" to set pid to the unix id of process The_app as Unicode text
do shell script "kill " & pid
end tell
end try
end MM_Quitter



On 26 May 2015, at 4:33 am, Fred Diepeveen <email@hidden> wrote:

Hi, maybe some can help on this issue:

  1. My script counts and selects mail in a specific mailbox "notfound"
  2. It counts 2 mail messages through  set lastMessage to (get count of messages of mailbox "INBOX" of account notfoundaccount)
  3. Some work is done 
  4. Messages are moved to a folder trough move theMessage to mailbox "SweepDone" of account notfoundaccount -- a folder contained by another folder
  5. All's working well but then:
  6. Running the same script again, it finds 2 messages with are in the sweepDone folder. Inbox is empty. 
  7. QUESTION: how can I stop mail and applescript finding messages in the "inbox" of the account? The messages are moved to the folder sweepDone. I even tried to move the messages to an other account but mail is still finding the messages




Q
Que
Thanks and regards .

Fred Diepeveen
email@hidden
+31 652002500



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
References: 
 >Applescript counting mails keeps counting mail in other folders (From: Fred Diepeveen <email@hidden>)

  • Prev by Date: Re: 'Make new attachment' dilemma
  • Next by Date: Re: 'Make new attachment' dilemma
  • Previous by thread: Re: Applescript counting mails keeps counting mail in other folders
  • Next by thread: Using multiple keyboard commands
  • Index(es):
    • Date
    • Thread