Same script won't run on different computers?

I’m running a script to clear an error message in Mail.

This script runs fine on my Powerbook G4 under 10.4.11 and Mail 2.1.3:

tell application "System Events"
	tell process "Mail"
		if exists window "test" then
			tell application "Mail" to activate
			delay 1
			key code 36 --the RETURN key to ok the dialog
			--OR
			--keystroke "." using command down --to cancel the dialog
			
		end if
	end tell
end tell


BUT, it won’t run on my iBook G4 under 10.4.11 and Mail 2.1.3. The script does not see the window “test” and returns a ‘false’ if I run the script above.

In this case, this is the script I must use:


set Trigger to 0
tell application "Mail"
	activate
	if exists window "test" then set Trigger to 1
end tell
if Trigger is 1 then
	tell application "System Events"
		tell process "Mail"
			delay 1
			key code 36 --the RETURN key to ok the dialog
			--OR
			--keystroke "return" using command down --to cancel the dialog
		end tell
	end tell
end if

In the Powerbook I tried to ‘break’ the script by removing all my script additions but that did not make any difference.

I’m stumped. Anyone got any ideas?

FYI, this is all part of a larger script that’s printing and sending email notices to different ppl when certain events happen on the iBook. If for some reason the full text could be helpful I’m happy to post it, but the problem exists in these smaller scripts so I don’t think it can be something elsewhere in the larger script.

Cheers!
Michael

Hello,

In the first code example, the process “Mail” might not actually even be running, which would hamper the operation of any commands.

Ah! I didn’t state that it is always running on the iBook G4 (where the script won’t run properly). It’s not the frontmost application, but it’s up and running.

Cheers!
Michael

Hi.

It sounds as if you might not have enabled GUI Scripting on your iBook.

GENIUS! PURE GENIUS!!!

Michael

After running this script and playing around with it I made an interesting discovery.

The full version of this script sends an email, but if there is no internet connection when it is sent then the email comes back with an error “could not connect, timed out on port 25”…that’s where the script tidbit I’ve posted here comes into play: it clears the error so the email can be sent once the internet connection is restored.

Here’s the issue: if the internet connection is restored BEFORE the error is cleared (I suspect Mail must sense the reconnecction in some form) the email will sit in the outbox and will remain unsent until someone actually opens it and tells it to send. All other automatic activity in Mail takes place normally including the sending of newly created emails. Sorta reminds me of Cinderella sitting in the basement while everyone else gets to go to the ball…hehe

Hope this tidbits helps someone somewhere out there.

Cheers,
Michael