NAME
NUREG::Automation::JS - JavaScript script execution with Adobe Programs
VERSION
version 0.03
SYNOPSIS
use NUREG::Automation::JS;
my $result = javascript('Adobe InDesign CS4',
'/path/to/file.js',
{ param => 'value', foo => 42 } );
# OR:
my $result = javascript('Adobe InDesign CS4',
[ lines of javascript ],
{ param => 'value', foo => 42 } );
# OR:
my $result = javascript('Adobe InDesign CS4',
{
# specify direct javascript source
source => 'source code',
# -OR- give a file for execution
file => '/path/to/file.js',
# specify a function to call (default 'main')
function => 'function_to_call',
# arguments to script (will convert to JSON)
args => { foo => 'bar' },
# specify a timeout in seconds
timeout => 1800,
# quit app before script starts (default = no)
quit_app_before => 0,
});
JAVASCRIPT
the anatomy of a typical JavaScript could look like:
#include "json_args.js"
function main(args) {
// do something with args -- which is a hash
// return anything
return { bla: 42, status: 'whatever' }
}
or simple inline statements like:
function do_something() {
// ...
}
do_something();
// a return value (either numeric, empty string or valid JSON)
'';
Gotchas
There is no include-path and the #includepath directive does not work. Thus, every included JavaScript must have either an absolute path or must reside in the same directory as the main JavaScript. Looks like there is no way around.
SUBROUTINES
javascript
execute a javascript in an app
applescript
execute applescript code
to_utxt
convert a string into a multiline string that savely encodes everything right.
if a var name is given as a second argument, the string is stuffed into the given variable. Long strings are split into parts.
set_open3_mode
set if call to osascript should be using open3 or simple open command open3 is the default but has shown difficulties when used with launch agents so you should set open3_mode to 0. beware, using simple open doesn't get you any results back!
AUTHOR
Wolfgang Kinkeldei, <kinkeldei@nureg.de>
LICENSE
This library is free software, you can redistribute it and/or modify it under the same terms as Perl itself.