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!
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
...
Copy link to clipboard
Copied
Rom,
According to the license terms FrameMaker must not be used in automatic way → FrameMaker Server.
Please note: answers 2 and 3 from the top of my head - not tested at all.
Copy link to clipboard
Copied
Hi Klaus,
I appreciate your response! Never heard or used Bridge. Will look into it. Thanks!
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.
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 ();
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!
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.)
Copy link to clipboard
Copied
Thank you for the explanation, Rick!
Copy link to clipboard
Copied
Question 2: doc is local but I can pass it to other functions as an argument:
processDoc (doc);
Copy link to clipboard
Copied
Thanks, Rick!
I was sure local variables can only be used within a function in which they are defined.
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.