It seems like you cannot do this via scripting. I tried to do the entire relinking of previous and next commands before updating the menus but that gives the same result. What is still open is the option to configure a different menu set via the menu configuration files. Or creating a new menu and adding all menus from the current File menu to that new one, pushing your own command in at the right time, tne removing the old File menu. It may be a lot of work but it should be doable that way.
It seems to me like Adobe needs to build some capability here for us scripters. It should not be too difficult for their programmers to add an option to AddCommandToMenu that will allow the user to specify after which menu item the new command (or submenu or separator) should go.
I think the disconnect is that a single command can be on multiple menus. So, when you have this:
var saveAsCmd = app.GetNamedCommand("Save");
you get the Save command object. But before you can move it, you have to be able to specify which menu it is on. This is how it is done with FrameScript:
Get Object Type(Command) Name('Save') NewVar(saveAsCmd); Get Object Type(Menu) Name('FileMenu') NewVar(fileMenu); New Command Name('SaveAsFm8') Label('Save As FM 8...') NewVar(newCmd) EventProc(SaveAsFm8); // Here is the missing item in ExtendScript. This identifies which // menu the Save command is on before you move the new // command relative to it. Set saveAsCmd.Menu = fileMenu; Set newCmd.PrevMenuItemInMenu = saveAsCmd;
The FDK is similar in that it provides a way to identify the menu object that the existing command is on:
saveAsCmd = F_ApiGetNamedObject(FV_SessionId, FO_Command, "Save"); fileMenu = F_ApiGetNamedObject(FV_SessionId, FO_Menu, "FileMenu"); newCmd = F_ApiDefineCommand(1, "SaveAsFm8", "Save As FM8...", ""); F_ApiAddCommandToMenu(fileMenu, newCmd); // Move the command so that it comes right after Save. // Notice the parent File menu is specified in the command below. F_ApiSetId(fileMenu, newCmd, FP_PrevMenuItemInMenu, saveAsCmd);
So it appears that the missing link is the ability to specify the parent menu of the existing command. Hopefully, someone from Adobe can confirm this, and if it is the case, they can provide a fix.