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.
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
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.