I had no doubt you had tested the script before posting it.
There seems however to be an issue with my computer (old iMac G4).
I created a new user and I am starting with fairly clean Mail.app install, just in case.
I have played a bit with the delays increasing step-by-step to 0.7, 1, 1.5, 2.5 with no apparent change in behaviour.
Mail.app opens and becomes the front app but no menu nor window pops up to shows further activity, is that normal?
I had in turn tried the script on English locale but, again, no difference.
It just hangs without doing anything.
Mail.app doesn’t apparently get any input from the running script and I can keep using the app while the script runs.
Nailing down this one seems harder than I thought…
In Mail 1.x.x the position of the menus could be different. Edit: Stupid me, as far as I remember there weren’t smart mailboxes in Mail 1
Try to comment out a portion of the script to see where it fails
e.g.
activate application "Mail"
tell application "System Events"
tell process "Mail"
click menu item 14 of menu 1 of menu bar item 6 of menu bar 1
(*
repeat until exists checkbox 1 of window 1
delay 0.5
end repeat
tell window 1
set value of text field 1 to "MyNewSmartMailBox"
tell pop up button 1
click it
delay 0.5
click menu item 1 of menu 1
end tell
delay 0.5
tell scroll area 1
tell pop up button 1
perform action "AXPress"
delay 0.5
click menu item 6 of menu 1
end tell
end tell
end tell
*)
end tell
end tell
PS: the script should work independent of the system language
I found it, in the italian system there is no window “New smart maibox” but a sheet
Try this
activate application "Mail"
tell application "System Events"
tell process "Mail"
click menu item 14 of menu 1 of menu bar item 6 of menu bar 1
tell window 1
repeat until exists sheet 1
delay 0.5
end repeat
tell sheet 1
set value of text field 1 to "MyNewSmartMailBox"
tell pop up button 1
click it
delay 0.5
click menu item 1 of menu 1
end tell
delay 0.5
tell scroll area 1
tell pop up button 1
perform action "AXPress"
delay 0.5
click menu item 6 of menu 1
end tell
end tell
end tell
end tell
end tell
end tell
OK, just to show you what I see in my copy of Mail.app have a look here, perhaps you can spot any significant differences.
As for the latest version of your script, modifying item 14 into 13, as I said, prompts me for a window asking to set the rules.
Once I have done that, it creates the smart folder.
Would be nice to automate also this final touch…
I’ll try
Ciao
/Pieter
UPDATE: for your reference, I just noticed that this is the result in the AppleScript box:
Perhaps that gives you further clues as to what has to be added to make sure that all mail addressed to: “mymaillist@example.com” shows up in the smartbox
Thanks for the screenshot.
The point is, if you have at least one IMAP account, there is an additional menu entry “Sincronizza.”
So I’ve changed the script to retrieve the information about the IMAP accounts and adjust the menu item number
tell application "Mail"
activate
set ExistsIMAP to ((count imap accounts) > 0) as integer
end tell
tell application "System Events"
tell process "Mail"
click menu item (13 + ExistsIMAP) of menu 1 of menu bar item 6 of menu bar 1
tell window 1
.
Edit: The settings in the script above were only for example
This should do, what you want
tell application "Mail"
activate
set ExistsIMAP to ((count imap accounts) > 0) as integer
end tell
tell application "System Events"
tell process "Mail"
click menu item (13 + ExistsIMAP) of menu 1 of menu bar item 6 of menu bar 1
tell window 1
repeat until exists sheet 1
delay 0.5
end repeat
tell sheet 1
set value of text field 1 to "MyNewSmartMailBox"
delay 0.5
tell scroll area 1
tell pop up button 1
perform action "AXPress"
delay 0.5
click menu item 2 of menu 1
end tell
delay 0.5
set value of text field 1 to "mymaillist@example.com"
end tell
click button 1
end tell
end tell
end tell
end tell
Actually, it showed some activity at the first run before deleteng the smartbox that had been previously created.
I could see the menus popping up and choices being made althouth, I was left with the usual window asking for the rules to be set.
After I cancelled the smartboxes, the script hangs as before, i.e. it’s probably again pointing towards the wrong item.
It now crosses my mind that perhaps the item count in the menu list is made using also the submenus like, for instance, the connection status or other as shown here, the number of wich may vary according to the number of boxes.
Hum, makes me wonder what writing a complex program is like as this was supposed to be trivial stuff.
Again, thanks a lot for you valuable assistance.
Much appreciated.
/Pieter
UPDATE: further to your update, I have modified accordingly and it works great now. You are a champion!
And next time I drive to the Gottard I will stop by and buy you a beer…
Hum, I am real sorry to come back on this matter but after I run it succesfully the first time, it doesn’t appear to work anymore.
Closing/restarting the apps makes no difference and so is restarting the computer.
What the hell is going on here?? @#%!!
Sounds like the hardest part is not writing the program but debugging it.
Kind of frustrating…
/Pieter
UPDATE: yet another update, hopefully the last one.
What happens exactly is I start the script and it hangs as at the beginning.
If now I right click on mail.app to manually create a smart folder, the script takes over and completes automagically everything.
Looks like it is waiting for an event that doesn’t happen.
This is correct.
If a smartbox already exist, the script runs ok.
If you set new values as name or rules, it will change the existing smartbox accordingly but in order to work it apparently needs to find an existing smart box.
So, what it does is, again, modifying an existing smartbox.
Can you confirm this at least?
/P
UPDATE: Changing Item number from 13 to 12, solves the issue pretty much as before.