I want to disable the page setup and print menu options when my application initially starts up. After entering data into a window and clicking the button to continue, then I want to enable the printing feature.
I have the following code in an awake from nib event
if name of theObject is "mainMenu" then
set enabled of menu item "saveMappingMenuOption" of menu "mainMenu" to false
set enabled of menu item "pageSetupMenuOption" of menu "mainMenu" to false
set enabled of menu item "printMenuOption" of menu "mainMenu" to false
end if
In the code I’m disabling my “save” feature as there is nothing to save until after the first window just like nothing to print. I’m not getting an error, and the save feature does get disabled. But the page setup and print options do not disable.
Has anyone run across this problem and found a solution? I’m guessing the code is correct and that maybe I need to modify something else to override the print option. Or maybe I need to have this processed in a different event handler?
You are correct, the problem is not in your code. It’s in the way you’ve got your app set up. What I’m assuming is that you’ve created a custom routine for your “Save” button, but you’re using the default “runPageLayout:” and “print:” connections provided by the project template. Any time you use a cocoa connection in interface builder, such as the two mentioned above, you probably will lose your ability to manage them via your applescript. They essentially stop listening for calls to modify them by your scripts. To get around this you must do two things. First, disconnect menu items from the default connections. Second, connect each menu item to it’s ‘choose menu item’ handler, and then use a “call method” to get the functionality you want. Here is the code I used (using your variable names) that got the job done for me… including some slightly streamlined code for your menu item state toggling…
(* Tell the menu items to disable, same for enable with "true" *)
tell menu "mainMenu" of main menu
set enabled of menu item "saveMappingMenuOption" to false
set enabled of menu item "pageSetupMenuOption" to false
set enabled of menu item "printMenuOption" to false
end tell
(* Attach to menu items in place of default connections *)
on choose menu item theObject
if name of theObject is "printMenuOption" then
call method "print:"
else if name of theObject is "pageSetupMenuOption" then
call method "runPageLayout:"
end if
end choose menu item
Thanks. I am not sure if I understood your explanation clearly. I thought I did and had things working. But now I seem to have made very menu item under the File option disabled and setting enabled to true does not seem to enable it.
Maybe I need to delete the menu item and recreate it. Maybe I accidentally messed something else up.
Tried that and still have all menu options disabled. I’ll keep you posted…