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

Programmatically adding extendscript to the Script Catalog

Participant ,
Feb 15, 2023 Feb 15, 2023

Copy link to clipboard

Copied

Hi everyone,

 

I've got 3 questions for the FM scripting mavens:

 

Is there a programmatic way (maybe via command line) to launch Framemaker and run a specific extendscript without first manually adding this extendscript to the catalog or transferring it to the Autorun mode? 

 

Alternatively, is there a way to lauch Framemaker via an extendscript?

 

Is there a way to run/call an extendscript from another extendscript?

 

Thank you for your responses in advance!

TOPICS
Scripting

Views

567

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

Community Expert , Feb 15, 2023 Feb 15, 2023

Question 3: If you create scripts, namespace them, and put them in the startup folder

C:\Users\<UserName>\AppData\Roaming\Adobe\FrameMaker\<Version>\startup

where <UserName> is your windows login name and <Version> is the FrameMaker version, then the scripts will load into memory when FrameMaker starts. Then you can call one script's functions from another script. For example, here is a main script that calls another one using it's namespace (which is an object) and the function name:

#target fr
...

Votes

Translate

Translate
Community Expert ,
Feb 15, 2023 Feb 15, 2023

Copy link to clipboard

Copied

Rom,

According to the license terms FrameMaker must not be used in automatic way → FrameMaker Server.

  1. The only known run-time parameter is -reg to start FM and fill the registry to allow double click on FM files to start FM.
  2. ExtendScript runs within FM or at least Bridge. Maybe FM coud be started from a script in Bridge.
  3. «Is there a way to run/call an extendscript from another extendscript?» This should be possible via the execution (opening) of the pertinent script file.

Please note: answers 2 and 3 from the top of my head - not tested at all.

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
Participant ,
Feb 15, 2023 Feb 15, 2023

Copy link to clipboard

Copied

Hi Klaus,

 

I appreciate your response! Never heard or used Bridge. Will look into it. Thanks!

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
Community Expert ,
Feb 15, 2023 Feb 15, 2023

Copy link to clipboard

Copied

Question 2: ExtendScript has a bunch of File properties and methods, so it should be possible to create and invoke a batch file that will launch FrameMaker and possibly pass it a FrameMaker document or book to open. I haven't done this, but it should be possible.

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
Community Expert ,
Feb 15, 2023 Feb 15, 2023

Copy link to clipboard

Copied

Question 3: If you create scripts, namespace them, and put them in the startup folder

C:\Users\<UserName>\AppData\Roaming\Adobe\FrameMaker\<Version>\startup

where <UserName> is your windows login name and <Version> is the FrameMaker version, then the scripts will load into memory when FrameMaker starts. Then you can call one script's functions from another script. For example, here is a main script that calls another one using it's namespace (which is an object) and the function name:

#target framemaker

var CP_ABC = CP_ABC || {};

CP_ABC.main = function () {

    var doc;
    
    doc = app.ActiveDoc;
    if (doc.ObjectValid () === 1) {
        processDoc (doc);
    }
};

CP_ABC.processDoc = function (doc) {

    // Do stuff here.
    
    // Then call the other script that is in memory.
    CP_XYZ.processDoc (doc);
};

CP_ABC.main ();

Here is the script whose function is being called:

#target framemaker

var CP_XYZ = CP_XYZ || {};

CP_XYZ.main = function () {

    var doc;
    
    doc = app.ActiveDoc;
    if (doc.ObjectValid () === 1) {
        processDoc (doc);
    }
};

CP_XYZ.processDoc = function (doc) {

    // Do stuff here.

};

CP_XYZ.main ();

 

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
Participant ,
Feb 16, 2023 Feb 16, 2023

Copy link to clipboard

Copied

Hi Rick,

 

Thank you for your input and for the sample code!

I've never heard about namespaces used in Extendscript. That's interesting.

2 questions:

- What does  || {} mean in the variable declaration?

- "doc" is a local variable of the main function, so how can one use it in another function (processDoc() in this case)?

 

Thanks again!

 

 

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
Community Expert ,
Feb 16, 2023 Feb 16, 2023

Copy link to clipboard

Copied

ExtendScript is just Adobe's extension of core JavaScript. The Namepace pattern is simply a way to minimize global variables in the ExtendScript environment. For example, if I have two scripts in the startup folder with a processDoc function, the last one that is loaded will overwrite the first, which is clearly not good.

 

Question 1: I want to create a JavaScript object in order to "namespace" the properties and functions of my script. I can use this to create the object:

 

var CP_ABC = {};

 

but what if CP_ABC already exists because I have created it earlier? Then I will end up overwriting the existing object. But if I use this

 

var CP_ABC = CP_ABC || {};

 

and CP_ABC already exists, then I won't overwrite it. (If the left side of the or operator (||) is true, then the right side is ignored; if the left side is false, then the right side is used.)

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
Participant ,
Feb 18, 2023 Feb 18, 2023

Copy link to clipboard

Copied

LATEST

Thank you for the explanation, Rick!

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
Community Expert ,
Feb 16, 2023 Feb 16, 2023

Copy link to clipboard

Copied

Question 2: doc is local but I can pass it to other functions as an argument:

 

processDoc (doc);

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
Participant ,
Feb 18, 2023 Feb 18, 2023

Copy link to clipboard

Copied

Thanks, Rick!

I was sure local variables can only be used within a function in which they are defined.

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
Community Expert ,
Feb 15, 2023 Feb 15, 2023

Copy link to clipboard

Copied

Question 1: FrameMaker ExtendScript has a Notify function that can listen to various events as they occur and then trigger a function, for example. In your case, if you figure out how to launch FrameMaker and open a particular document, a script could monitor the open document event and then launch a particular script, based on the document's name, etc. (see the answer to Question 3). It's a bit complex to share here, but I have used it in dozens of scripts with good success.

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