This has me stumped.

This works…


activate application "Mail"
tell application "Mail"
	try
		set IsVisible to visible of window 1
		if IsVisible is false then
			tell application "System Events" to tell application process "Mail" to tell menu bar 1 to tell menu bar item 3 to tell menu 1 to tell menu item 2
				click
			end tell
		end if
	on error
		tell application "System Events" to tell application process "Mail" to tell menu bar 1 to tell menu bar item 3 to tell menu 1 to tell menu item 2
			click
		end tell
	end try
end tell

But this doesn’t…


activate application "Mail"
tell application "Mail"
	try
		set IsVisible to visible of window 1
		if IsVisible is false then
			openWindow()
		end if
	on error
		openWindow()
	end try
end tell

on openWindow()
	tell application "System Events" to tell application process "Mail" to tell menu bar 1 to tell menu bar item 3 to tell menu 1 to tell menu item 2
		click
	end tell
end openWindow

Would somebody mind explaining why before it drives me bonkers :P.

Thanks

Santa

Santa:

Simply a matter of remembering to use the term [my] when calling a handler from inside of a tell block:


activate application "Mail"
tell application "Mail"
	try
		set IsVisible to visible of window 1
		if IsVisible is false then
			my openWindow()
		end if
	on error
		my openWindow()--You need to use the term [my] when accessing a handler outside of a tell block.
	end try
end tell

on openWindow()
	tell application "System Events" to tell application process "Mail" to tell menu bar 1 to tell menu bar item 3 to tell menu 1 to tell menu item 2
		click
	end tell
end openWindow

Hi santa

Been looking into scripting mail app lately just wondered what you where trying to acheive…

Not much happens with either script that i can tell…
What are you trying to do?

cheers

Thanks Craig Such a simple answer :slight_smile:

Pidge, what do you mean? Have you dowloaded the script and found it doesn’t work after setting the four parameters?

It works in the background, so seems to do nothing except dial up if you aren’t already online, otherwise it leaves the connection open and just calls Mail in the background.

Only comes forward if you have new mail, and the dialog window set to ‘true’, otherwise you have to bring Mail forward yourself.

It works like this so as not to interrupt any workflow.

Feedback appreciated.

Santa

Hi Santa

My apologies!!! Doh!
My Excuse! it was late!
Sorry…

Just out of interest you can also say “of me”

openWindow() of me

which will do the same as “my…”

cheers

G’day Pidge, apology accepted :confused:

Thanks for the extra tip.

You probably found version 1.2 buggy, but I’ve posted 1.3, which turned out still has minor bugs.

My excuse? I’m on broadband, so checking the dial-up bit is a hassle.

I’ve got version 1.4 sitting on my desktop, which appears to be bullet proof, and also works on broadband. Perhaps famous last words.

Why broadband? Because I could do it, and it allows the user to check mail less often than the max 1 hour of Mails settings.

Regards

Santa