Disable menu item don't work!

Ok, i’m trying to disable a menu item in a pop-up button. I have the code:

set enabled of menu item "type3" of popup button "formats" of window "newfile" to false

I put that in ‘awake from nib’, so when the window appears, the user can’t choose it. I also have about 5 more similar lines of code to disable other menu items. It works(sorta), then gives some darn error. I could have sworn I made this work before, but I doesn’t work now. :frowning:

Hopefully the ASBBS can help me out again…

Hi there,
Try putting this in your ‘awake from nib’ handler before those statements.

set auto enables items of popup button 1 of window "newfile" to false

Apparently there’s supposed to be a checkbox for this somewhere in IB, but I haven’t found it.
Hope this works.

Doesn’t seem like it. What could I be doing wrong?

Hi ThreeDee912,

try:

	tell popup button "formats" of window "newfile"
		set auto enables items of it to false
		set enabled of menu item "type3" of menu of it to false
	end tell

D.

Is that an “NSSomeDarnError: 666(13)”, or a “NSCantHandleNoobieRequest” error? :rolleyes:
The errors are actually quite valuable sometimes in helping to determine what the problem is. Perhaps if you tell us what the error is, we can then give you more than a shot-in-the-dark guess as to what’s happening.

You might also consider that popup buttons do not have menu items… their menu does. While popup buttons do have a “current menu item” property that can be used to reference the current item, it’s not valid to reference item’s of a popup button directly when manipulating their properties programmatically. Perhaps you need to reference your menu item’s as such…

set enabled of menu item "type3" of menu of popup button "formats" of window "newfile" to false

j

I should have known better. I tell that to people at other message boards when then have problems.

Apple’s docs say that’s the old way of doing it. It’s not in the latest docs, but my slightly older docs say: “Starting with AppleScript Studio version 1.2, when referring to the menu of a popup button, a script can say menu item 1 of popup button 1 instead of the longer menu item 1 of menu of popup button 1, although the longer form still works.”

Thanks for the help though.

Ok, It works, but I still get an error when it ‘wakes from nib’. It’s “NSRecieverEvaluationScriptError: 3(1)”

That error appears about 6 times before I can do anything else.

BTW, this is the only code in the project file. The names of the objects were changed a bit:

-- DMG Press.applescript
-- DMG Press

--  Created by Chris on Tue Aug 22 2006.
--  Copyright (c) 2006 BigPixel Software. All rights reserved.

on awake from nib theObject
	tell popup button "formats" of window "newDI"
		set auto enables items of it to false
		set enabled of menu item "disable1" of menu of it to false
		set enabled of menu item "disable2" of menu of it to false
		set enabled of menu item "disable3" of menu of it to false
	end tell
end awake from nib

on choose menu item theObject
	(*Add your script here.*)
end choose menu item

I tried it and it worked here. Maybe you have a typo somewhere in the menu item’s names?

Btw: Depending on how many menu items you want to disable, you could shortcut the script:

on awake from nib theObject
   tell popup button "formats" of window "newDI"
       set auto enables items of it to false
       set enabled of (menu items whose name starts with "disable") of menu of it to false
    end tell
end awake from nib

It did work, but I got that error. I’m not sure where it is coming from!

Thanks for the quick-disable tip though.

What I’m guessing is that you’ve got all of the menu item’s themselves wired up to the ‘awake from nib’ handler. You only need to connect the window (or the popup button) to the handler. Disconnect the items, and you’ll find that you stop getting the errors. Here’s my code from the test project I made up…

on awake from nib theObject
	if name of theObject is "window" then
		tell popup button "somePopUpButton" of window "window"
			set auto enables items to false
			set enabled of menu item "menuItem4" to false
		end tell
	end if
end awake from nib

j

YES! It works! :smiley:

Thank you everyone!