Adobe 65009333 Scripting Guide - Page 23

Running scripts at start-up, Session and main script execution

Page 23 highlights

Scripting Features Running scripts at start-up 23 var myJavaScript = "app.scriptArgs.setValue(\"ScriptArgumentA\", \"This is the first script argument value.\");\r"; myJavaScript += "app.scriptArgs.setValue(\"ScriptArgumentB\", \"This is the second script argument value.\")"; var myScriptArgumentA = app.scriptArgs.getValue("ScriptArgumentA"); var myScriptArgumentB = app.scriptArgs.getValue("ScriptArgumentB"); alert("ScriptArgumentA: " + myScriptArgumentA + "\rScriptArgumentB: " + myScriptArgumentB); if(File.fs == "Windows"){ var myVBScript = "Set myInCopy = CreateObject(\"InCopy.Application.CS4\")\r"; myVBScript += "myInCopy.ScriptArgs.SetValue \"ScriptArgumentA\", \"This is the first script argument value.\"\r"; myVBScript += "myInCopy.ScriptArgs.SetValue \"ScriptArgumentB\", \"This is the second script argument value.\""; app.doScript(myVBScript, ScriptLanguage.visualBasic); } else{ var myAppleScript = "tell application \"Adobe InCopy CS4\"\r"; myAppleScript += "make script arg with properties{name:\"ScriptArgumentA\", value:\"This is the first script argument value.\"}\r"; myAppleScript += "make script arg with properties{name:\"ScriptArgumentB\", value:\"This is the second script argument value.\"}\r"; myAppleScript += "end tell\r"; app.doScript(myAppleScript, ScriptLanguage.applescriptLanguage); } var myScriptArgumentA = app.scriptArgs.getValue("ScriptArgumentA"); var myScriptArgumentB = app.scriptArgs.getValue("ScriptArgumentB"); alert("ScriptArgumentA: " + myScriptArgumentA + "\rScriptArgumentB: " + myScriptArgumentB); Running scripts at start-up To run a script when InCopy starts, put the script in the Startup Scripts folder in the Scripts folder (for more information, see "Installing scripts" on page 7). NOTE: Scripts run in the session ExtendScript engine when InCopy starts can create objects and functions that will be available to other scripts for the duration of the session. For more information, see "Session and main script execution" on page 23. Session and main script execution InCopy has two ways to run a JavaScript: session and main. These names correspond to the ExtendScript "engine" used to run the script. By default, when you run an InCopy JavaScript, the script is interpreted and executed by the "main" ExtendScript engine, which is destroyed when the script completes execution. Script objects created by the script do not persist. Scripts run in the session engine can create objects that persist until you close InCopy. You can refer to these objects from other scripts run in the session engine. To set the session engine as the target of an InCopy JavaScript, add the following line to the start of your script. #targetengine "session"

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88

Scripting Features
Running scripts at start-up
23
var myJavaScript = "app.scriptArgs.setValue(\"ScriptArgumentA\", \"This is the first
script argument value.\");\r";
myJavaScript += "app.scriptArgs.setValue(\"ScriptArgumentB\", \"This is the second
script argument value.\")";
var myScriptArgumentA = app.scriptArgs.getValue("ScriptArgumentA");
var myScriptArgumentB = app.scriptArgs.getValue("ScriptArgumentB");
alert("ScriptArgumentA: " + myScriptArgumentA + "\rScriptArgumentB: " +
myScriptArgumentB);
if(File.fs == "Windows"){
var myVBScript = "Set myInCopy = CreateObject(\"InCopy.Application.CS4\")\r";
myVBScript += "myInCopy.ScriptArgs.SetValue \"ScriptArgumentA\", \"This is the
first script argument value.\"\r";
myVBScript += "myInCopy.ScriptArgs.SetValue \"ScriptArgumentB\", \"This is the
second script argument value.\"";
app.doScript(myVBScript, ScriptLanguage.visualBasic);
}
else{
var myAppleScript = "tell application \"Adobe InCopy CS4\"\r";
myAppleScript += "make script arg with properties{name:\"ScriptArgumentA\",
value:\"This is the first script argument value.\"}\r";
myAppleScript += "make script arg with properties{name:\"ScriptArgumentB\",
value:\"This is the second script argument value.\"}\r";
myAppleScript += "end tell\r";
app.doScript(myAppleScript, ScriptLanguage.applescriptLanguage);
}
var myScriptArgumentA = app.scriptArgs.getValue("ScriptArgumentA");
var myScriptArgumentB = app.scriptArgs.getValue("ScriptArgumentB");
alert("ScriptArgumentA: " + myScriptArgumentA + "\rScriptArgumentB: " +
myScriptArgumentB);
Running scripts at start-up
To run a script when InCopy starts, put the script in the Startup Scripts folder in the Scripts folder (for more
information, see
Installing scripts
” on page 7
).
N
OTE
:
Scripts run in the session ExtendScript engine when InCopy starts can create objects and functions
that will be available to other scripts for the duration of the session. For more information, see
Session
and main script execution
” on page 23
.
Session and main script execution
InCopy has two ways to run a JavaScript:
session
and
main
. These names correspond to the ExtendScript
“engine” used to run the script.
By default, when you run an InCopy JavaScript, the script is interpreted and executed by the “main”
ExtendScript engine, which is destroyed when the script completes execution. Script objects created by
the script do not persist.
Scripts run in the session engine can create objects that persist until you close InCopy. You can refer to
these objects from other scripts run in the
session
engine. To set the
session
engine as the target of an
InCopy JavaScript, add the following line to the start of your script.
#targetengine "session"