• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

People's Champ ,
Nov 14, 2022 Nov 14, 2022

Copy link to clipboard

Copied

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-beca...

 

Is it just me?

 

Loic

TOPICS
Scripting

Views

268

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

People's Champ , Nov 14, 2022 Nov 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 

Votes

Translate

Translate
Community Expert ,
Nov 14, 2022 Nov 14, 2022

Copy link to clipboard

Copied

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);

 

 

Screen Shot 9.png

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Nov 14, 2022 Nov 14, 2022

Copy link to clipboard

Copied

LATEST

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 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines