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

.idjs script, UXPScript Error! Error String: app is not defined

Engaged ,
Jan 21, 2024 Jan 21, 2024

I'm trying to learn to use .idjs and I keep runing into the error: UXPScript Error! Error String: app is not defined. It's a very simple script to test and I think it should work but it doesn't. Anyone have any guidence. 

let myInDesign = require("indesign");
let myDoc = myInDesign.app.activeDocument;
let myLayer = myDoc.layers.item("Layer 1");

  if (!myDoc.layers.itemByName("DIGITAL").isValid) {
    myDoc.layers.add({ name: "DIGITAL" });
  }

  if (myDoc.layers.itemByName("Layer 1").isValid) {
  myLayer.remove();
  }
TOPICS
Scripting
789
Translate
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

Engaged , Jan 21, 2024 Jan 21, 2024

Ok, well this is embarrassing. I had duplicated the the script to work on it from vscode and instead of working on the one in inDesign I added it to vscode. Doh!  So I did get it to work now if I could just get it to work from the uxp plugin. Thanks for the help all. 

Translate
Community Expert ,
Jan 21, 2024 Jan 21, 2024

Try defining the app at the start 

 

#target indesign

Translate
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
Engaged ,
Jan 21, 2024 Jan 21, 2024

Unfortunately that doesn't work.

Translate
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
Community Expert ,
Jan 21, 2024 Jan 21, 2024

Hi @davidn5918184, I just ran your code on ID 19.1, MacOS 14.2.1, and it worked as expected (created a layer and removed the other). I executed the script via the script panel. Can you give more info on your set up? Are you running via the script panel?

- Mark

Translate
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
Engaged ,
Jan 21, 2024 Jan 21, 2024
LATEST

Ok, well this is embarrassing. I had duplicated the the script to work on it from vscode and instead of working on the one in inDesign I added it to vscode. Doh!  So I did get it to work now if I could just get it to work from the uxp plugin. Thanks for the help all. 

Translate
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