Scripting the Open Recent Menu Item under the File Menu

Here’s the code I have developed so far (edited by JL on Nov 12, 2007):


script openRecentFile
	
	on choose menu item theFile
		-- whatever
	end choose menu item
	
end script

on addRecentItem(recentItem)
	
	-- title of the main menu -- "myMenus"
	
	set fileMenu to the second menu item of the main menu
	-- title="File"
	
	set openRecentMenu to the third menu item of the sub menu of the fileMenu
	-- title="Open Recent"
	
	set recentFilesMenu to openRecentMenu's sub menu
	-- count of menu items of recentFilesMenu -- "1" initially
	-- title of first menu item of recentFilesMenu -- "Clear Menu"
	
	-- gExcelDoc is a Global
	set recentFile to ¬
		make new menu item at the end of the menu items of the recentFilesMenu ¬
			with properties {title:gExcelDoc, name:recentItem, enabled:true}
	-- title of first menu item of recentFilesMenu -- "Nancy Love (2011) applescript"
	-- title of second menu item of recentFilesMenu -- "Clear Menu"
	
	set script of recentFile to openRecentFile
	
end addRecentItem

The (NEW) challenge is that my “make new menu item …” statement does work with “at the end”, but does not work with “at the beginning”. That is, the 'Clear Menu" item for “at the beginning” remains dimmed and as the solitary sub menu item. With “at the end”, the file gExcelDoc shows and overwrites “Clear Menu”.

HAALP!