Automation Engine 22
Running Scripts in Automation
Engine
05 - 2023
Automation Engine
Contents
1. Scripting Concept...........................................................................................................................................3
2. The Script Runner Tool..................................................................................................................................5
3. Installing Script Runner.................................................................................................................................6
4. Configuring Script Runner.............................................................................................................................8
5. The Run Script Task..................................................................................................................................... 10
6. Script Runner on macOS - Examples...........................................................................................................13
6.1. AppleScript - Example 1....................................................................................................................... 13
6.2. AppleScript - Example 2......................................................................................................................16
6.3. Shell Script - Example......................................................................................................................... 19
7. Script Runner on Windows - Examples.......................................................................................................24
7.1. Windows Script Example 1...................................................................................................................24
7.2. Windows Script Example 2................................................................................................................. 26
7.3. Batch File Example.............................................................................................................................. 31
8. Using ExtendScript (macOS & Windows)................................................................................................... 35
8.1. Adobe Applications on Windows: Run Script Runner as an Application (Not as a Service)................... 35
8.2. ExtendScript in Adobe Illustrator - Example 1.....................................................................................35
8.3. ExtendScript in Adobe Illustrator - Example 2.................................................................................... 38
8.4. ExtendScript in Adobe Photoshop - Example......................................................................................41
9. PowerShell Examples (macOS & Windows)............................................................................................... 44
10. Scripting Samples...................................................................................................................................... 46
ii
1
Automation Engine
1. Scripting Concept
Automating Desktop and Other Applications
Although Automation Engine already offers a wide set of tools to create custom workflows, it is still
possible that you miss some functionality or maybe to support less standard graphics format that you
still use or receive.
This is why Automation Engine also offers custom scripting: you can write scripts (small programs)
that typically represent actions that operators do interactively in their graphic desktop applications..
Once you created that script, the Run Script task enables to insert that task into your normal
workflows. This is also how you can automate your desktop applications.
Some examples:
To automate actions in desktop applications like Adobe Illustrator, Photoshop, InDesign (Server),
etc. (via ExtendScript on macOS and Windows).
To convert files into a format that Automation Engine tasks support. For example converting non-
PDF compatible AI files into PDFs.
Attention: It is up to the user to verify that his intended use of the offered automation
functionality is compliant with any third party license agreement and/or other restrictions
applicable to any non-Esko products.
Supported Script Types
AppleScript (macOS), a scripting language created by Apple that facilitates automated control over
script-able Mac applications.
ShellScript (macOS), the shell scripting supported by the Mac Terminal.
Batch files (Windows), a Windows script file that consists of a series of commands to be executed
by the command-line interpreter.
Windows Script (Windows), a Microsoft VBScript or JScript.
ExtendScript (macOS and Windows), a type of JavaScript enriched with Adobe extensions that can
be executed by certain Adobe applications.
Attention: When scripting Adobe applications, the Script Runner tool on Windows no
longer supports 32 bit versions of those applications.
PowerShell (macOS and Windows), a cross-platform task automation solution made up of a
command-line shell, a scripting language, and a configuration management framework.
Attention: When installing PowerShell 7.x on Windows, make sure the option ' Add
PowerShell to Path Environment Variable' is checked.
Tip: Using native PowerShell scripts makes it easier to capture an error status of your
script than when you run them via a Windows Batch file (a script error will end up on the
error output pin of the script task).
3
1
Automation Engine
The Script Runner Tool
Executing such scripts starts in the Run Script task. One of the settings in that task is to choose if the
script will be executed by a separate Script Runner tool (that you installed earlier on a Mac or Windows
client computer), or if the script can run on the Automation Engine server itself (in the 'on-board Script
Runner').
When, for example, your script is a Windows batch file, it will be possible to run it on the Automation
Engine server itself. But when the script needs to interact with a Mac (Adobe) application, it will require
help from a standalone Script Runner that you also installed on that Mac.
Learn more in The Script Runner Tool on page 5.
Extra Information and Tips available as KB articles
Because the area of scripting is often about customization, the examples in this documentation do not
cover all use cases.
We therefore advise to also check Esko's Knowledge Base for articles on this topic.
4
2
Automation Engine
2. The Script Runner Tool
The Automation Engine server itself does not actually run your custom script: the AE task
communicates with a tool called Automation Engine Script Runner.
Attention: As mentioned in Scripting Concept, the 'Run Script' task can run the script on the AE
server itself (a Windows Script or batch file) or it could use a standalone Script Runner tool on a
Mac or Windows client.
Here 's an overview of the workflow when a standalone AE Script Runner is used:
1.
The Run Script task sends a request to run the selected script on its input file(s). The task can
communicate optional script parameters and also defines the output folder for the resulting file(s).
2.
The selected Script Runner processes the request and runs the script.
3.
The Script Runner sends the results back to the Run Script task.
4.
The workflow continues with the outputs from this Run Script task.
5
3
Automation Engine
3. Installing Script Runner
Important: As mentioned in the chapter on SaaS, installing and using external Script Runner
tools is not supported when your AE is a SaaS setup.
Follow these steps to install the Script Runner tool.
These client applications and other tools can be downloaded:
1.
Like the main client applications, also the Script Runner tool can be installed from an AE browser
client. Go to http://<AEserverName>:9000/#/downloads ). In its home page, go to the tab
Apps & Tools > Tools and Download Script Runner.
2.
After downloading, double-click the ‘dmg’ file (Mac) or the 'exe' file (Windows) to start the
installation. Follow the instructions in the Assistant (Mac) or Installshield Wizard (Windows).
3.
Check the tool's preferences to make sure it is running on that computer:
On Windows, open Start > All Programs > Esko > Automation Engine Script Runner >
Preferences.
On macOS, open Applications > Automation Engine Script Runner > Esko > Automation Engine
Script Runner > Script Runner Preferences.
In the Script Runner Preferences dialog, you can:
Start / Stop the Script Runner (or just check if it is running).
Note: On Windows, this will run the Script Runner as a 'Service'. Learn about (the
need for) other methods in Adobe Applications on Windows: Run Script Runner as an
Application (Not as a Service) on page 35.
Enable / disable Start at login
View / change the Port that the Script Runner is communicating with
View / change the default folders for (types of) scripts.
Example (on Windows):
6
3
Automation Engine
Attention: The above shown folders are local, on the Script Runner computer. Learn how
you can (also) store them centrally in Configuring Script Runner on page 8.
7
4
Automation Engine
4. Configuring Script Runner
The Automation Engine server needs to know where your installed your Script Runner(s). You could for
example have 2 Macs dedicated to run scripts and also have the Automation Engine server itself have
some Windows scripts or batch files running.
1.
Install Script Runner on the client computers that will run scripts. Learn more in Installing Script
Runner on page 6.
2.
In a Pilot, go to Tools > Configure.
3.
Go to the category Scripts. (As mentioned earlier, this configuration topic does not appear in a
SaaS setup)
4.
Now define which computers will run the scripts. Press Insert or choose File > New to add one.
5.
Give a suitable name to that Script Runner. Press F2 or choose File > Rename.
6.
In the Host field, enter the computer name or IP address of the Script Runner computer.
7.
Enter the Port used to connect this computer to your Automation Engine server.
By default, this is 1983.
8.
Agent: In an AE SaaS setup, the communication between a local Script Runner and the AE server in
the data center happens via a local Agent. Select an Agent from the list. Learn more in the chapter
on SaaS and in The Run Script Task on page 10.
8
4
Automation Engine
9.
Click Test Connection. You should now see a list of all available scripts on that computer or see a
message 'No scripts available'.
These are the scripts that the Run Script Task will let you choose from when you have selected that
Script Runner configuration in the ticket.
You can store scripts on a local client (Script Runner) or centrally on the Automation Engine server:
Local: You can store scripts on your local client computer on the folder specific for script type.
But note that Automation Engine does not back up these local scripts. It can be useful however
to only have them local when you are still writing and testing a script or when you do not intend
to give access to other Script Runners in your network.
Note: The default location on a client computer is (macOS) /Library/Scripts/
Esko and (Windows) C:\Esko\bg_data_fastserverscrrunnt_v100\Scripts .
Central: Alternatively, you can store your scripts in a central Automation Engine system folder.
This option is suitable when you want to make your scripts available to all configured Script
Runners. They will then also be part of your Automation Engine backup.
Note: The default location on the AE server is C:\Esko
\bg_data_fastserver_v100\Scripts. The subfolder names indicate the type of
script.
10.
Choose Save (from the menu of the Configure panel).
11.
Select the Configure panel's category Scripts (not an item you added, but one level higher). On
this level you see a dialog where you can choose Download Scripts to download all scripts from all
configured Script Runner tool(s) and centralize them onto the Automation Engine server. This is
done to have a central library that will also be part of your server configuration backup.
Note: When local scripts would overwrite central ones, you will be asked to confirm.
9
5
Automation Engine
5. The Run Script Task
Note: Learn about the concept and the setup of custom scripts in Scripting Concept on page
3.
This task contacts a Script Runner tool to run a script on the input file(s).
Note: Since AE 22.03, this task can also be started on an empty token (for example without
input files).
1.
Run on: Choose the Script Runner tool that you configured in the Configure panel.
2.
Select the Script Type. The types are different, depending if the selected Script Runner runs on a
macOS or a Windows computer:
a) Script Runner on macOS: You can choose from
AppleScript
Shell Script
ExtendScript.
PowerShell Script
Note: On macOS, PowerShell has to be installed. As long as PowerShell is not
installed on a Mac script runner node, it will not show up in the list of script types.
Installing PowerShell on macOS is documented on Microsoft web pages, for example
these.
b) Script Runner on Windows: You can choose from
10
5
Automation Engine
Batch File
ExtendScript
Windows Script
Windows Script (32-bit).
Note: Since AE 16.1, you can only install the Script Runner tool on a 64 bit host, but
you can still run 32 bit Windows scripts by specifying the script type as 'Windows
Script (32 bit)'.
PowerShell Script
Note: On Windows, PowerShell comes with the OS. In most cases you get an old
version like v5.1, but you can manually update to a recent version (for example v7.2)
3.
Select the Application. This field helps to find the right application, especially when you have
multiple versions installed. The drop down list is a default list that you can edit.
On macOS, this is the (original) name of the .app file of that application
On Windows, this is the "Target location" that appears when you ask the "Properties" of that
application. An example:
Tip: It is possible that you do not have to enter the full name, but minimally the part
that will help the task to recognize which of the multiple versions you want. For example
when you both have a CS and a CC version, then the year and the bit version do not have
to be mentioned extra (because those are only mentioned after the 'CS' or 'CC' part).
4.
Select the Script File. You can select one from the drop-down list, enter a path or/and use
SmartNames.
5.
Transfer input file(s) to the Script Runner:
When not selected, the Script Runner will receive a file specification referring to a file on an
Automation Engine Container.
When selected, the input file(s) are transferred to the Script Runner computer through the
connection made by the server when sending the script instructions.
This option is:
11
5
Automation Engine
disabled and selected in an AE SaaS setup (the use of an Agent requires the input files to be
transferred to the Script Runner). Learn more below on using this task in an AE SaaS setup.
disabled and deselected when the script is run on the Automation Engine server itself.
6.
When the script needs one or more optional parameter(s), enter them in Script Parameters. Click
Add and type the parameter.
Note: Learn more details and see some examples in the next pages.
About using this task in an AE SaaS setup:
In an AE SaaS setup, the local Script Runner is configured to use a local Agent for its communication
with the AE SaaS server in the data center.
The technical details of how this works:
The task resolves task parameters and then submits the script request to the Agent. The task waits
until the script has been executed by the Script Runner via the Agent
The agent downloads the input files from the AE SaaS Containers to a temporary location on the
Agent computer.
The Agent opens a socket connection to the local Script Runner and submits the script request
together with the input data as a self-contained package to the Script Runner, i.e. no Windows
sharing is needed between the Agent computer and the Script Runner ; the only requirement is that
the Agent must be able to open a socket connection to the configured port of the Script Runner.
When the Script Runner has executed the script:
The Agent downloads the generated output files to a temporary location on the Agent computer
(%BG_DATA_FASTSERVERAGENTNT_V100%\runscript), i.e. no additional network
connection needed.
The output files are uploaded to the AE SaaS Container in the folder indicated in the ticket of the
Run Script task.
The result of the execution of the script is added to the task details.
The task is stopped using the exit value of the script.
All temporary files are removed from the file system of the Agent.
12
6
Automation Engine
6. Script Runner on macOS - Examples
Warning: These sample scripts are provided as-is with no warranty of fitness for a particular
purpose. These scripts are solely intended to demonstrate techniques for accomplishing
common tasks. Additional script logic and error-handling may need to be added to achieve the
desired results in your specific environment.
It is up to the user to verify that his intended use of the offered automation functionality is
compliant with any third party license agreement and/or other restrictions applicable to any
non-Esko products.
6.1. AppleScript - Example 1
AppleScript is a scripting language that enables direct control of script-able applications and of
many parts of the macOS. An AppleScript-able application is one that makes its operations and data
available in response to AppleScript messages, called Apple events.
We recommend using AppleScript because:
it is highly integrated into the macOS
it is supported by a lot of third party applications
it very accessible to scripting beginners.
1.
Open the AppleScript Editor and add following code:
Option Description
main This function will be called by the Script Runner. Only the code in this main
function gets executed.
inputs The first argument of the main function: a list of input file paths (type: list of
strings).
13
6
Automation Engine
Option Description
outputFolder Second argument of the main function: the folder where AE expects the
script’s result files. AE will continue the flow with the files you write in this
folder. If you leave this folder empty, AE will continue the flow with the
inputs of the Run Script task (type: string).
params Third argument of the main function: additional script parameters injected
into the script via the Run Script ticket (type: list of strings).
log Extra log information in the Run Script task details.
return “OK” This will communicate to the Run Script task that everything went fine.
Other possibilities are return “Warning” and return “Error”.
2.
Save this code as an AppleScript text file in the Script Runners AppleScript folder (default: /
Library/Scripts/Esko/AppleScript) or in the Automation Engine AppleScript folder.
Note: Script Runner supports ‘Text’ format. Therefore it is essential to change the file
format to ‘Text’.
3.
You can add following code to test this script locally in the AppleScript Editor. Save the file and click
Run to execute the script.
14
6
Automation Engine
Notice the ‘Hello, World!’ and ‘OK’ result in the event log. The Script Runner does not interpret the
test code in your script. It will execute the contents of the main function and ignore the rest. You
can keep any test code for future local testing.
4.
In the Pilot, go to Files view where you can select a file and open a New Task. Choose the Run Script
task, modify its settings and launch the task.
15
6
Automation Engine
Learn more in The Run Script Task on page 10.
Note that the ‘Hello, World!’ in the task details and ‘OK’ state correspond with log “Hello,
World!”’ and ‘return “OK”’ in the script.
6.2. AppleScript - Example 2
In this example, we use AppleScript to copy every input file with a size smaller than the size specified in
the script parameters to the output folder. To do that, we use inputs, outputFolder and params in
the AppleScript.
First, we illustrate how to duplicate files without the size restriction and then we proceed with the
actual case.
1.
Open the AppleScript Editor and add the below shown code. This code is aimed to iterate through
the list of inputs. It enables you to handle the inputs one by one, via the ‘input’ variable.
16
6
Automation Engine
2.
You can modify the Script as shown below to duplicate the files to a specified output folder
without size restrictions. Save this code as an AppleScript text file in the default AppleScript
folder of Script Runner (default: /Library/Scripts/Esko/AppleScript) or in the Automation Engine
AppleScript folder.
3.
Add the file size check in the code as shown below. This will duplicate the file when the input file
size is smaller than the maximum size from the script parameters. If this condition is not met, it will
add an entry in the log and there will be "Warning". Save the file.
17
6
Automation Engine
4.
In the Pilot, go to Files view, select the files to be copied and open a New Task. Choose the Run
Script task, modify its settings and launch. This modified ticket will duplicate every selected file
which is smaller than 10 MB to the current job’s Script Output folder. In this example, we executed
this task for two files (BigBox.pdf: 22 MB and SmallLabel.pdf: <1 MB).
18
6
Automation Engine
‘SmallLabel.pdf’ is duplicated into the job’s 'ScriptOutput' folder. ‘BigBox.pdf’ was too big to
duplicate (> 10 MB). Therefore, the task ended in a ‘Warning’ state and added an entry in the task
details.
6.3. Shell Script - Example
In this example, we use a Shell Script to copy every input file with a size smaller than the specified size
in the script parameters to the output folder.
19
6
Automation Engine
1.
Open a text editor and add the below shown code. When the Script Runner executes this code, $1
(the script’s first argument) will contain a string of input file paths separated by : . The code splits
up the concatenated file paths into a real list. This helps to iterate through the list and handle the
Run Script task’s inputs one by one.
2.
Write the code as shown below. This script copies the input to the output folder if the input’s file
size is smaller than the maximum size from the script parameters. If the size of the file is bigger, it
adds an entry in the log and makes sure the task ends in ‘Warning’ state (via exit value ‘1’). Save this
code as a text file to the Script Runner's Shell folder (default: /Library/Scripts/Esko/Shell) or to
the Automation Engine Shell folder.
20
6
Automation Engine
$1 First Shell Script argument: the Run Script task’s inputs. A string of input file
paths, separated by ‘:’.
$2 Second Shell Script argument or output folder: This is the folder where
Automation Engine expects the script’s result files. AE will continue the flow with
the files you write in this folder. If you leave this folder empty, AE will continue the
flow with the inputs of the Run Script task.
$3, $4, $5, … Remaining Shell Script arguments: additional script parameters which you can
inject into the script via the Run Script task.
21
6
Automation Engine
exitValue Ending Status of the task
0 OK
1 Warning
2 Error
3.
In the Pilot, go to Files view, select a file and open a New Task. Choose the Run Script task, modify
its settings and launch. This modified ticket will duplicate every selected file which is smaller than
10 MB to the current job’s Script Output folder. In this example, we executed this task for two files
(BigBox.pdf: 22 MB and SmallLabel.pdf: <1 MB).
‘SmallLabel.pdf’ is duplicated into the job’s Script Output folder. ‘BigBox.pdf’ was too big to duplicate
(> 10 MB). Therefore, the task ended in ‘Warning’ state (due to exitValue=1 in the code) and added
an entry in the task details.
22
6
Automation Engine
23
7
Automation Engine
7. Script Runner on Windows - Examples
Warning: These sample scripts are provided as-is with no warranty of fitness for a particular
purpose. These scripts are solely intended to demonstrate techniques for accomplishing
common tasks. Additional script logic and error-handling may need to be added to achieve the
desired results in your specific environment.
It is up to the user to verify that his intended use of the offered automation functionality is
compliant with any third party license agreement and/or other restrictions applicable to any
non-Esko products.
7.1. Windows Script Example 1
1.
Open a text editor and add the below shown code:
Function Main The function that will be called by the Script Runner. Script
Runner executes only the code in this main function.
inputs First argument of main function: a list of input file paths
(type: list of strings).
outputFolder Second argument of the main function: the folder where
AE expects the script’s result files. AE will continue the
flow with the files you write in this folder. If you leave this
folder empty, AE will continue the flow with the inputs of
the Run Script task (type: string).
24
7
Automation Engine
params Third argument of the main function: additional script
parameters injected into the script via the Run Script
ticket (type: list of strings).
WScript.Echo This puts some extra log info in the Run Script task details
and log. This call prints text to the Console and adds a
newline character without Script Runner context.
Main = “OK” This communicates to the Run Script task that everything
went fine. Other possibilities are Main = “Warning”
and Main = “Error”.
2.
You can test this script locally by adding the code shown below. Save this file. Open command
prompt. Change the directory to the script’s parent directory. Run command ‘cscript
MyHelloWorld.vbs’.
This will produce the output ‘Hello, World!’ to the console. The Script Runner does not interpret the
test code in your script. It will execute the contents of the main function and ignore the rest. You
can keep your test code for future local testing.
3.
In a Pilot, go to Files view, select a file and open a New Task. Choose the Run Script task, modify its
settings and launch the task.
25
7
Automation Engine
Note that the ‘Hello, World!’ in the task details and ‘OK’ state are corresponding with
WScript.Echo “Hello, World!” and Main = “OK” in the script.
7.2. Windows Script Example 2
In this example, we use Windows Script to copy every input file with a size smaller than the size
specified in the script parameters to the output folder. We use inputs, outputFolder and params
in the script to achieve our objective.
First, we illustrate how to duplicate files without the size restriction and then we proceed with the
actual example.
26
7
Automation Engine
1.
Open a text editor and add the below shown code. This code is aimed to iterate through the list of
inputs. It enables you to handle the inputs one by one, via the ‘input’ variable.
2.
You can modify the Script as shown below to duplicate the files to a specified output folder without
size restrictions. Save this code as a text file with ‘.vbs’ extension (VBScript) in the Windows
Script folder of Script Runner (default: C:\Esko\bg_data_fastserverscrrunnt_v100\Scripts
\WindowsScript) or in the Automation Engine WindowsScript folder.
27
7
Automation Engine
3.
Add the file size check in the code as shown below. This will duplicate the file when the input file
size is smaller than the maximum size from the script parameters. If this condition is not met it will
add an entry in the log and there will be "Warning". Save the file.
28
7
Automation Engine
4.
In a Pilot, go to Files view, select the files to be copied and open a New Task. Choose the Run Script
task, modify its settings and launch. This modified ticket will duplicate every selected file which is
smaller than 10 MB to the current job’s 'ScriptOutput' folder. In this example, we executed this task
for two files (BigBox.pdf: 22 MB and SmallLabel.pdf: <1 MB).
29
7
Automation Engine
‘SmallLabel.pdf’ is duplicated into the job’s 'ScriptOutput' folder. ‘BigBox.pdf’ was too big to
duplicate (> 10 MB). Therefore, the task ended in ‘Warning’ state and added an entry in the task
details.
30
7
Automation Engine
7.3. Batch File Example
In this example, we use a Batch file to copy every input file with a size smaller than the size specified in
the script parameters to the output folder.
1.
Open a text editor and add the below shown code. This code is aimed to iterate through the list
of inputs. It enables you to handle the inputs one by one, via the command %1 (the script’s first
argument) will contain a string of input file paths, separated by ‘;’.
2.
You can modify the Script as shown below to duplicate the files to a specified output folder with a
size check. Save this code as a text file with ‘. bat ’ extension in the Script Runner Batch File Folder
(default: C:\Esko\bg_data_fastserverscrrunnt_v100\Scripts\BatchFile) or in the Automation
Engine 'BatchFile' folder.
31
7
Automation Engine
%1 First batch file argument: the Run Script task’s inputs. A string of input file paths, separated
by ‘;’.
%2 Second batch file argument or output folder: the folder where AE expects the script’s result
files. AE will continue the flow with the files you write in this folder. If you leave this folder
empty, AE will continue the flow with the inputs of the Run Script task.
32
7
Automation Engine
%3, %4,%5 Remaining batch file arguments: additional script parameters, injected into the script via
the Run Script task.
Exit
value
Ending Status of the task
0 OK
1 Warning
2 Error
3.
In a Pilot, go to Files view, select the files to be copied and open a New Task. Choose the Run Script
task, modify its settings and launch. This modified ticket will duplicate every selected file which is
smaller than 10 MB to the current job’s Script Output folder. In this example, we executed this task
for two files (BigBox.pdf: 22 MB and SmallLabel.pdf: <1 MB).
‘SmallLabel.pdf’ is duplicated into the job’s 'ScriptOutput' folder. ‘BigBox.pdf’ was too big to
duplicate (> 10 MB). Therefore, the task ended in ‘Warning’ state and added an entry in the task
details.
33
7
Automation Engine
34
8
Automation Engine
8. Using ExtendScript (macOS & Windows)
8.1. Adobe Applications on Windows: Run Script Runner as
an Application (Not as a Service)
When you use ExtendScript on Windows, you can avoid problems while accessing your user specific
settings such as Adobe applications' Presets , Actions, etc. by stopping the Script Runner service and
running it as an application for the logged in user (who also defined the Adobe settings).
Follow these steps to do this:
Open Start > All Programs > Esko > Automation Engine Script Runner > Preferences.
Stop the Script Runner and deselect Start at login (which actually means ‘Start as service’) and
Close Preferences.
Start it as a console application by double clicking its executable in the Script
Runners program folder >\bin_ix86\egscrrun.exe. For example C:\Esko
\bg_prog_fastserverscrrunnt_v141\bin_ix86\egscrrun.exe
8.2. ExtendScript in Adobe Illustrator - Example 1
ExtendScript is JavaScript extended for Adobe CS/CC applications. Adobe provides the ExtendScript
Toolkit (ESTK): a complete IDE (integrated development environment) to program ExtendScript. Learn
more about Adobe scripting resources in the Adobe Scripting Center.
Attention: As mentioned in the introduction, Adobe (Windows) 32 bit applications are no
longer supported on a standalone Script Runner tool.
1.
Open the ExtendScript Toolkit and add the below shown code. Save this code in the Script Runners
ExtendScript folder. The default location is : /Library/Scripts/Esko/ExtendScript for a Script
Runner on Mac or C:\Esko\bg_data_fastserverscrrunnt_v100\Scripts\ExtendScript on Windows.
Alternatively, you can save them in the ExtendScript folder of Automation Engine.
35
8
Automation Engine
Main This function will be called by the Script Runner. Only the code in this main
function gets executed.
Inputs First argument of main function: a list of input file paths (type: list of strings).
outputFolder Second argument of the main function: the folder where AE expects the script’s
result files. AE will continue the flow with the files you write in this folder. If you
leave this folder empty, AE will continue the flow with the inputs of the Run Script
task (type: string).
params Third argument of main function: additional script parameters, injected into the
script via the Run Script ticket (type: list of strings).
$.writeln This writes extra log information in the Run Script task details and log. Without
Script Runner context this call prints text to the Console, and adds a newline
character.
alert This registers some extra log info in the Run Script task details and log. Without
Script Runner context this call displays an alert box.
return “OK”; This communicates to the Run Script task that everything went fine. Other
possibilities are Return = “Warning” and Return = “Error”.
2.
To test the script locally in the ExtendScript Toolkit, add below shown code, save and run the script.
36
8
Automation Engine
As a result, ‘Hello, World!’ and ‘OK’ are shown in the Console and the alert box pops up:
The Script Runner does not interpret the test code in your script. It will execute only the contents of
the main function and ignore the rest. You can keep your test code for future local testing.
3.
In the Pilot, go to Files view, select a file and open a New Task. Choose the Run Script task, modify
its settings and launch the task.
37
8
Automation Engine
Note that the ‘Hello, World!’ in the task details and ‘OK’ state are corresponding with
$.writeln("Hello World!")and Return = “OK” in the script.
8.3. ExtendScript in Adobe Illustrator - Example 2
In this example we use ExtendScript to Open a file in Illustrator and print it using a Print Preset. 
Note: Make sure you read this page first: Adobe Applications on Windows: Run Script Runner as
an Application (Not as a Service) on page 35.
Note: To prevent having to start up the Script Runner every time you log in, add its executable
to your users/systems Startup Items.
1.
Define a My Print Preset in your Adobe Illustrator application.
2.
Open the ExtendScript Toolkit and add the below shown code. This code is aimed to iterate through
the list of inputs. It enables you to handle the inputs one by one, via the input variable.
38
8
Automation Engine
3.
To print every input file using a Print Preset from the script parameters in the Run Script task, write
the code as shown below. Save this code in the default ExtendScript folder (of Script Runner or of
Automation Engine).
39
8
Automation Engine
4.
In a Pilot, go to Files view, select a file and open a New Task. Choose the Run Script task, modify its
settings and launch the task.
40
8
Automation Engine
Launching this ticket will print the selected Illustrator files using the Print Preset specified as
script parameters (My Print Preset) in the task.
8.4. ExtendScript in Adobe Photoshop - Example
Note: These sample scripts are solely intended to demonstrate techniques for accomplishing
common tasks. Additional script logic and error-handling may need to be added to achieve the
desired results in your specific environment.
It is up to the user to verify thathis intended useof the offered automation functionality is
compliant with any third partylicense agreement and/or otherrestrictions applicable to any
non-Eskoproducts.
In this example, we illustrate a script that performs a Photoshop "action" and then produces
a JPEG output. The script 'EskoPSDoActionAndSaveasJPG.jsx' is available from the
sample scripts subfolder "ExtendScript" in /Library/Scripts/Esko (Mac) or C:\Esko
\bg_data_fastserverscrrunnt_v100\Scripts (Windows).
1.
You have to save the Set and Action in Photoshop. In this example we are using an action named
"Molten Lead" which is one of the "Default Actions" (folder) as Set (variable 2) and "Molten
Lead" as Action (variable 1).
2.
You can open the script with ExtendScript Toolkit to edit the script if required. However, in this
sample, we do not need to edit the script.
41
8
Automation Engine
3.
Edit the settings of the Run Script task as shown below:
a) Run on: is the name of the computer where your Automation Engine ScriptRunner is installed.
The name in this example is ShaletMac. Learn more about configuring and naming a Script
Runner in Configuring Script Runner on page 8.
b) Script Type: choose ExtendScript.
c) Script File: choose EskoPSDoActionAndSaveasJPG.jsx.
d) Script Parameters: Add the name of your Photoshop Action name followed by your Set. In this
example, Molten Lead; Default Actions
e) Save the task ticket.
4.
Launch the task:
a) Select a Photoshop file.
b) Right-click the file and browse for the ticket.
c) Click Launch.
42
8
Automation Engine
You will see that while the script starts to run on the Automation Engine server, Photoshop opens,
performs the actions, closes and continues the script. The result of this sample script is an
adjusted JPEG file.
43
9
Automation Engine
9. PowerShell Examples (macOS & Windows)
My First PowerShell
This one only returns the message between " ". See it appear in the task details (and log file).
Write-Host "Congratulations! Your script executed successfully"
Write Local Time to File
This one writes the local time of the executing computer in the task details and also in a .txt file on the
specified path.
Get-CimInstance -ClassName Win32_LocalTime | Out-File -FilePath C:\temp\localtime.txt
Some specifics for an AE task
This one shows some specifics that help in the context of an AE task:
CmdletBinding to capture the task's standard and custom parameters.
-split ‘:’ to split the list of input files (where more than one).
Returning a task exit status: 0 = OK, 1 = warning, 2 = error .
[CmdletBinding()]
Param
(
# Param1 help description
[Parameter(Position=0)][string]$inputfiles,
[Parameter(Position=1)][string]$outputFolder,
[Parameter(Position=2)][string]$Parameter1,
[Parameter(Position=3)][string]$Parameter2,
[Parameter(Position=4)][string]$Parameter3
)
# checks if variables are declared
Set-StrictMode -Version 2
#begin of main program
#$hostname = get-content env:computername
$hostname = hostname
Write-Host "Starting script example.ps1 on: ", $hostname
#show PowerShell version
Write-Host "PowerShell version: ", $PSVersionTable.PSVersion
Get-Date
Write-Host "Received input files", $inputfiles
$inputArray = $inputfiles -split ':'
$retval = 0
Write-Host "Number of input files: " $inputArray.length
$outstring = ""
foreach ($inputfile in $inputArray)
{
Write-Host "Handling input file: " $inputfile
44
9
Automation Engine
$lastWrite = Get-Item $inputfile | select LastWriteTime
$outstring = $outstring + $inputfile + " " + $lastWrite +"`r`n"
}
Write-Host "Pstsmeter 1: " $Parameter1
Write-Host "Pstsmeter 2: " $Parameter2
Write-Host "Pstsmeter 3: " $Parameter3
$outputname = $hostname + ".lst"
try
{
New-Item -Path $outputFolder -Name $outputname -ItemType "file" -Value $outstring -
ErrorAction Stop
}
catch {
Write-Output "An error occured while writing the output file"
#Write-Output $_
$errormessage = $_.Exception.Message
Write-Host $errormessage
$retval = 2
}
exit $retval
45
10
Automation Engine
10. Scripting Samples
Click this link to download a PDF containing some samples of scripts.
46