Skip to main content
Loic.Aigon
Legend
November 14, 2022
Answered

Can't get scriptMenuAction to properly run (…the object no longer exists…)

  • November 14, 2022
  • 1 reply
  • 474 views

Hi everyone,

 

Trying to execute a menu addition and at the moment the event handler function is executed, I get the "

The requested action could not be completed because the object no longer exists". Thought I made something wrong but even the sample script from the official documentation throws the same error.
 
Tested on CC23, 22 et 19 with no luck.
 
This is the official sample from doc:
 

 

var mySampleScriptAction = app.scriptMenuActions.add("Display Message");
var myEventListener = mySampleScriptAction.eventListeners.add("onInvoke",
    function () { alert("This menu item was added by a script."); });
//If the submenu "Script Menu Action" does not already exist, create it.
try {
    var mySampleScriptMenu = app.menus.item("$ID/Main").submenus.item("Script Menu Action");
    mySampleScriptMenu.title;
}
catch (myError) {
    var mySampleScriptMenu = app.menus.item("$ID/Main").submenus.add("Script Menu Action");
}
var mySampleScriptMenuItem = mySampleScriptMenu.menuItems.add(mySampleScriptAction);

 

 
I saw this post but it didn't help much.

https://community.adobe.com/t5/indesign-discussions/the-requested-action-could-not-be-completed-because-the-object-no-longer-exists/m-p/12623082

 

Is it just me?

 

Loic

This topic has been closed for replies.
Correct answer Loic.Aigon

Hi @rob day 

Yes I do use a targetengine instruction. I think the "issue" came from the fact I was doing debugging in VSCode and probably targeting a wrong enginename (thus bypassing the one declared into the script). Once run from the script palette, everything went fine indeed.

Loic 

1 reply

rob day
Community Expert
Community Expert
November 14, 2022

Hi Loic, Have you tried adding a #targetengine at the top? This works for me in CC2021:

 

 

//targetengine for listeners
#targetengine "session";

var mySampleScriptAction = app.scriptMenuActions.add("Display Message");
var myEventListener = mySampleScriptAction.eventListeners.add("onInvoke",
    function () { alert("This menu item was added by a script."); });
//If the submenu "Script Menu Action" does not already exist, create it.
try {
    var mySampleScriptMenu = app.menus.item("$ID/Main").submenus.item("Script Menu Action");
    mySampleScriptMenu.title;
}
catch (myError) {
    var mySampleScriptMenu = app.menus.item("$ID/Main").submenus.add("Script Menu Action");
}
var mySampleScriptMenuItem = mySampleScriptMenu.menuItems.add(mySampleScriptAction);

 

 

Loic.Aigon
Loic.AigonAuthorCorrect answer
Legend
November 14, 2022

Hi @rob day 

Yes I do use a targetengine instruction. I think the "issue" came from the fact I was doing debugging in VSCode and probably targeting a wrong enginename (thus bypassing the one declared into the script). Once run from the script palette, everything went fine indeed.

Loic