mailbox question

Thanks again for continuous feedback.

I had no doubt you had tested the script before posting it. :slight_smile:
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… :frowning:

/P

Are you using Panther?

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

No no, of course not. :expressionless:

I am on the latest availble system release.

All updates and patches applied.

/P

Model: iMac G4/700
AppleScript: 1.10.7
Browser: Safari 522.12.1
Operating System: Mac OS X (10.4)
Mail.app Versione 2.1 (752/752.2)

Running the above, produces the following in to the results box:

Which appears OK to me.

/P

UPDATE: no it isn’t right. I need not to “Modifica casella smart” but the next one item, i.e. “Crea casella smart”
Does that give you any clues?

We need “Nuova cassella smart.”

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

Hello Stefan, not sure what you mean with this suggestion however, we sure are making some progress by trial and error here:

changing item 14 to item 13 on this line:

tell process "Mail"
       click menu item 14 of menu 1 of menu bar item 6 of menu bar 1

Prompts me to a first window asking to give the smartbox a name and create some rules.

Here it stops.
Looks like the menus in your app are different, probably due to the addition of plugins.

Are you perhaps using Junk Matcher or other plugins that change the menus?

That would explain what is happening.

/Pieter

I have indeed installed Junk Matcher, but I thought, only the Messagio menu will be affected

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… :smiley:

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 :stuck_out_tongue:

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

Nice try but it doesn’t work. :slight_smile:

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… :smiley:

Unfortunately GUI scripting is no trivial stuff at all.

PS after update: I’m glad it works finally :slight_smile:

Then you better pass San Bernardino :wink:

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… :confused:

/Pieter

UPDATE: yet another update, hopefully the last one. :expressionless:
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.

In the Editor box I found this:

Does this give you any clues?

Sorry for that, I’ve just created three smart mailboxes consecutively with the script, no problems

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.