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

embed extendscript in idml

Explorer ,
Nov 07, 2019 Nov 07, 2019

Hi, is it possible to embed Extendscript into an idml file ?
And if possible, can it be executed automatically when the idml file is opened ?

TOPICS
Scripting
394
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 ,
Nov 07, 2019 Nov 07, 2019

A "yes" for both.

You can add the code as string e.g. to the document by using the label property.

That's the same when using script labels on page items in GUI.

 

You can do it also with the object document using ExtendScript methods insertLabel() with two arguments:

A key string and a value string.

 

Later you can exract it using method extractLabel() with the key string as argument on a document.

The extracted string can be executed with e.g. doScript() or eval().

 

If you want to automate this when opening an InDesign document or an IDML file you could do that with an eventlistener that is looking after "afterOpen" or with an idleTask that is doing the job in the first moment InDesign is doing nothing after the IDML file is opened and a defined period of time has gone by.

 

Here a tiny example:

 

var myCodeString = '''alert("Hello World!")''';

app.activeDocument.insertLabel( "keyForMyCodeString" , myCodeString  );
app.doScript( app.activeDocument.extractLabel( "keyForMyCodeString" ) );

 

Export that document to IDML and inspect designmap.xml. You will detect this:

 

	<Properties>
		<Label>
			<KeyValuePair Key="kAdobeDPS_Version" Value="2" />
			<KeyValuePair Key="keyForMyCodeString" Value="alert(&quot;Hello World!&quot;)" />
		</Label>
	</Properties>

 

Regards,
Uwe Laubender

( ACP )

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
Explorer ,
Nov 13, 2019 Nov 13, 2019

Thanks Uwe!

I have an additional question regarding relative paths in the embedded extendscript.
I want to provide a zip file that conatins the generated IDML and an images-folder. Then I want to place the images from that folder into the document. That works with absolute paths, but I don't know to which location our users will download the zip file. 
I tried to get the path to the document using app.activeDocument.filePath, but I get the message that documents that are not saved don't have a filepath. I get that message although I execute the Extendscript directly after opening the IDML.
Is there a way to use relative paths in Extendscript or is there another way to get the absolute path to the current document ?

 

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
New Here ,
Nov 14, 2019 Nov 14, 2019

How would I name the Startup Folder? Where would I place it?

And how would I name the Extendscript File that is executed at loading the idml File into Indesign?

 

I tried (Contents of Idml File):

/META-INF

/Masterspeads

/Resources

/Spreads

/Startup <----------------------------

/Startup/startme.jsx

/Stories

/XML

designmap.xml

mometype

 

How would be the syntax in the Jsx File?

I tried (for startme.jsx):

alert("hallo");

 

So far nothing gets executed.

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 ,
Nov 14, 2019 Nov 14, 2019
LATEST

Hi Markus,

you need a startup script OUTSIDE your IDML file that is looking for code in labels of an opened document to execute the code in the label. There is no way I do know to execute code by itself that comes with an InDesign document or an IDML file.

 

Regards,
Uwe Laubender

( ACP )

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