Creating submenus of Main Menu menu's dynamically

Greetings everyone. Does anyone know how to create sub menus of main menu items? For example, I want to create a new menu in my application programatically…

make new menu at end of menus of main menu with properties {title:"Test", name:"Test", enabled:true}

…which works fine. But what I want to do is be able to create a sub menu of the ‘Test’ menu, and populate IT with menu items. Here’s a diagram…

I want “Item 1” and “Item 2” to be items in a sub menu of “Test” named “Menu 1”. I’ve tried all sorts of things and it doesn’t want to let me make submenu’s…only menu items. I’m looking for something along the lines of…

(* Create the sub menu *)
make new menu item at end of menu items of menu "Test" of main menu with properties {title:"Main 1", name:"Main1", enabled:true}
(* Create each menu item *)
make new menu item at end of menu items of menu item "Main1" of menu "Test" of main menu with properties {title:"Item 1", name:"Item1", enabled:true}

I realize that this should be streamlined, but I wanted to elaborate on my code so you could see exactly what I’m doing. I’ll take obj-c calls too, but I can’t see a way to use them either. Ultimately, I want to take a list of lists like {{“a”,“b”,“c”},{“x”,“y”,“z”}} and create a menu out of it’s contents like…

Thanks in advance…
j

To create a submenu, you can use this method:

- (NSMenu *)make_submenu_to_menu:(NSMenu *)the_menu with_title:(NSString *)title with_icon:(NSString *)the_icon {
    NSMenu *new_menu;
    NSMenuItem *new_item;
    new_item = [[NSMenuItem allocWithZone:[NSMenu menuZone]] initWithTitle:title action:NULL keyEquivalent:@""];
    new_menu = [[NSMenu allocWithZone:[NSMenu menuZone]] initWithTitle:title];
    if(![the_icon isEqualToString:@""]) {
		[new_item setImage:[NSImage imageNamed]];
    }
    [new_item setSubmenu];
    [the_menu addItem];
    [new_item release];
    return new_menu;
}

And call it from your script via a “call method”. Then you can assign new menu items to the menu it returns.

Jon

(* Create the sub menu *)
make new menu item at end of menu items of menu "Test" of main menu with properties {title:"Main 1", name:"Main1", enabled:true}
(* Create each menu item *)
make new menu item at end of menu items of menu item "Main1" of menu "Test" of main menu with properties {title:"Item 1", name:"Item1", enabled:true}

Is there a way to not only give the menu item an applescript name but also assign it an event handler like

with properties {title:“Item 1”, name:“Item1”, enabled:true , event handler: “choose menu item”}

hmmmm

make new menu item at end of menu items of menu “myMenu” of main menu with properties {name:“MyMenuName”, title:“MyMenuName”, enabled:true}

isn’t even working for me. I’m getting NSReceiverEvaluationScriptError: 4 (1)

What’s up with that?

Never mind about the 4 (1) error got that fixed. It wasn’t event that line that was causing it.
Would still like to know about setting the event handler though.