NSReceiverEvaluationScriptError

Hi,

This applescript script worked fine until I performed security update SecUpd2005-009Ti to System 10.4.3.

tell application "Safari" to activate

tell application "System Events"
	tell application process "Safari"
		click menu item "Reset Safari." of menu "Safari" of menu bar 1
		try
			click button "Reset" of window 1
		end try
	end tell
end tell

Now it fails to perform, and returns this error:

System Events got an error: NSReceiverEvaluationScriptError: 4

Safari ver. 2.0.2
G-4 667 upgraded to 1.8 Ghz
1.5 Gigs RAM.

Any idea what the cause and remedy might be? Thanks much for all the hard work being accomplished on this website.

Thanks again,
Adonsa

Your script works fine here, Adonsa [Safari Version 2.0.2 (416.13)]. :confused:

In case it helps, this type of error is normally caused by an object that has been incorrectly referenced or named. If you haven’t altered the script in any way, try re-checking Safari’s current menu hierarchy and names. One common gotcha, for example, is the use of periods (3 characters: “…”) in place of an ellipsis (1 character: “.”) - or vice versa.

Make sure you check your universal access under system preferences. Enable access for assistive devices must be checked.

Good point, bonedoc. If access for assistive devices is not enabled, then the same error would result. :slight_smile:

Hi, Kai and Bonedoc, thanks much for the replies.

I made sure that the script has the ellipsis, not 3 dots
I made sure that universal access assistive devices is enabled.

The only thing monumental I had done between the last time the script worked, and when it ceased was that I installed the latest Apple security update (yes I did the permissions thing before and after the install). It’s really tough to imagine that a security upgrader would diddle with Applescript. I have no right to fingerpoint to the Apple upgrader, the problem could be coincidental.

I ran the script thru Script Debugger Demo and here’s what happened: Initially I thought that Applescript couldn’t find Safari, but looking at where the pointer stopped, it looks like Applescript can’t find Safari’s reset button anymore, even though it is, in fact, real.

While attempting to step thru the script, the pointer stopped here and wouldn’t let me go further, then the error was returned.

tell application “Safari” to activate

tell application “System Events”
tell application process “Safari”
----> click menu item “Reset Safari.” of menu “Safari” of menu bar 1
try
click button “Reset” of window 1
end try
end tell
end tell

Script Debugger’s Script Error window returned these errors at each of its 3 tabs:
The Message Tab displayed this error:
System Events got an error: NSReceiverEvaluationScriptError: 4

The partial Result tab returned this:
{}

The Application Tab returned this:
application “System Events”

I’m at a loss to do anything beyond wild speculation, so I’ll much appreciate any ideas/suggestions.
Thanks again, and Happy New Year,
Adonsa

Hi Kai and Bonedoc,

I applied my applescript script to the Opera web browser and the same error was returned. If I may speculate, it appears that Applescript is not getting along with System Events.

tell application “Opera” to activate

tell application “System Events”
tell application process “Opera”
click menu item “Delete Private Data.” of menu “Tools” of menu bar 1
try
click button “Delete” of window 1
end try
end tell
end tell

Thanks much,
Adonsa

Hi, Adonsa.

I don’t know if it’s the cause of your problem, but I think that menu “Safari” should belong to menu bar item “Safari” of menu bar 1, not to the menu bar directly.

Similarly with your Opera script.

That’s right, Nigel. The full reference here is:

menu item "Reset Safari." of menu "Safari" of menu bar item "Safari" of menu bar 1 of application process "Safari" of application "System Events"

Up to now, there’s been some latitude in the use of such references. Perhaps the security update “corrected” this, making it necessary to be absolutely precise…

I do hope you’re right about this being the possible cause - since I’d love to get to the bottom of this one! :slight_smile:

Kai and Nigel,

I was so hoping that was it. I tried both syntaxes,
ending with
tell application “Safari” to activate

tell application “System Events”
tell application process “Safari”
----> click menu item “Reset Safari.” of menu “Safari” of menu bar item “Safari” of menu bar 1 of application process “Safari” of application “System Events”
try
click button “Reset” of window 1
end try
end tell
end tell

Unfortunately (for me) the pointer stopped in the same place with the same errors returned again. Hmmmm.
I guess the syntaxes are fine, hitting the compile button returned no errors. But running or stepping - bummer.
I suspected that Applescript itself may be corrupt; I tested some mail scripts via Apple mail and they ran fine.

I think I’m dumping on you guys, or this thing’s elusive as hell. I really thank you for sticking with me on this. I did make sure that Applescript utility has GUI scripting enabled. For what it’s worth, I also tried rebuilding permissions, running disk repair (from another mounted volume), doing the cron stuff, running Onyx.

Maybe I’ll wake up in the middle of the night and think of something.

Thanks much,
Adonsa

I’ve no doubt it’s the latter, Adonsa. :slight_smile:

I’m only sorry that we haven’t been able to come up with the answer - but it sounds like you’re checking all the right things. Just as a matter of interest, does System Events return true (as it should) for this?

tell application "System Events" to UI elements enabled

Well, both versions work for me, and I have the same security update. But since Adonsa mentioned that he was running the script in Script Debugger, I wondered if SD might be less tolerant of the “incorrect” version than System Events itself. However, that doesn’t seem to be it. :frowning:

Not at all ” unless there’s something else in the script that you’re not telling us about. :wink: Your script should work. I suppose the next step would be a painstaking check of the small details, if you haven’t already done one.

  1. Visually check Safari’s “Safari” menu to make sure it still has a “Reset Safari.” item and that this isn’t greyed out.

  2. Try a progressive series of small, test scripts to find out exactly which part of the reference is failing:

tell application "Safari" to activate
tell application "System Events"
	application process "Safari" exists
end tell

If that returns ‘true’, then go on to:

tell application "Safari" to activate
tell application "System Events"
	tell application process "Safari"
		menu bar 1 exists
	end tell
end tell

Then:

tell application "Safari" to activate
tell application "System Events"
	tell application process "Safari"
		menu bar item "Safari" of menu bar 1 exists
	end tell
end tell

And so on, backing up through the reference to menu item “Reset Safari.”. If at any point you get the result ‘false’, that’s where either Safari or System Events has a problem, or where you’ve made some small typo in the test script. If you never get a ‘false’ result, that would suggest some problem with the original script ” either a previously undetected typo or an internal corruption.

Let us know how you get on. :slight_smile:

Hi Nigel,

They were true until this one - it returned a “false.”
tell application “Safari” to activate
tell application “System Events”
tell application process “Safari”
menu bar item “Safari” of menu bar 1 exists
end tell
end tell

OK, ummm, the script recognizes menubar 1, as it should. But it fails to recognize item “safari”, which is displayed on my Mac as the oil filled blue compass icon. Under System 9 and below, I could go in with ResEdit and ascertain the real name (maybe), but … could it be the real name of the Safari menu got diddled with? I’m uncertain how to determine the alpha name behind the compass icon.

Please forgive my “negative knowledge.” What System 10 utility should I use to go into Safari’s resource fork to look around to find my answer? My knowledge gets more negative 'cause I’m told there’s no longer any such thing as a resource fork. ouch!

Oops, almost forgot, I didn’t even download the Script debugger demo until this problem cropped up. Very expensive shareware fee.

Damn, I miss Hypercard. Oops, I’m getting off track.

Thanks much, guys, for your efforts to walk me through all this.

Adonsa

Aha. Are you saying that when Safari’s the frontmost application, the second menu in the menu bar is titled with an oil-filled blue compass icon instead of with the word “Safari” in bold type? That could be the vital clue we weren’t getting. Why on earth is it like that?

If that’s the case, what’s the second item in the list returned by this?

tell application "Safari" to activate
tell application "System Events"
	name of menu bar items of menu bar 1 of application process "Safari"
end tell

It may turn out that ‘menu “Safari” of menu bar item “Safari” on menu bar 1’ will have to be rendered as ‘menu 1 of menu bar item 2 of menu bar 1’.

Hi Nigel,

Wow: Here’s what it returns:
{“Apple”, missing value, “File”, “Edit”, “View”, “History”, “Bookmarks”, “Window”, “Help”, missing value, “Debug”}

And, yeah, the first item is the Apple icon, next is Safari’s compass icon, then File, Edit, etc.

The 2nd “missing value” is the PithHelmet menu icon. So uh, it looks like System Events doesn’t get along with menubar icons.

Also, I booted up to a separate external firewire bootup drive (also with System 10.4.3 and the latest Apple security upgrade), then I dismounted all other mounted volumes. The error did occur again under those conditions (much to my horror). This firewire bootup drive does not have pith helmet, so I think I can rule out Pith Helmet as the cause.

So, ummm, looks like System Events interprets Safari’s compass icon to … , well, I got no idea. Strange, strange, I defer to your wisdom.

Thanks, Nigel
Adonsa

Hi, Adonsa.

Well. I don’t know if your copy of Safari is corrupted, or whether you have something installed that shows the icon instead of the name in the menu bar. But unless there’s anything else missing, I suspect that referring to the menu by number rather than by name will work for you:

tell application "Safari" to activate

tell application "System Events"
	tell application process "Safari"
		click menu item "Reset Safari." of menu 1 of menu bar item 2 of menu bar 1
		try
			click button "Reset" of window 1
		end try
	end tell
end tell

Nigel, it worked! Wow! I owe you a beer!:slight_smile: Awesome :slight_smile:
I gotta figure out what startup item or system pref file is diddling with Safari.

Thanks very very much!
Happy New Year,
Adonsa

Nigel, I just found the cause, and, damn I should have caught that! Argggh!
Fruit Menu by Unsanity allows changing of the application menu to an icon; and I had it checked.
Prior to the security upgrade, Applescript didn’t mind, but after the security update
it did.

Soooo, I should be a good Macker and report the anomoly to Unsanity and to the MacFixit website.

Thanks much for all the hard work getting me “sort of” troubleshooting qualified.

Happy New Year,
Adonsa

And to you, Adonsa. :slight_smile: I’m glad the problem’s sorted. It’s also handy for the rest of us to know that this sort of situation can occur. I’m speculating, but it may be that if Fruit Menu was active when you ran the security update, its own chain of information may have been broken. I believe Apple recommends turning off system patching software before running system updates and upgrades. It’s remembering you’re using it that’s the problem! :rolleyes: