没有合适的资源?快使用搜索试试~ 我知道了~
Scripting InDesign CS3-4 with JavaScript
需积分: 10 7 下载量 136 浏览量
2013-10-18
16:38:20
上传
评论
收藏 1.28MB PDF 举报
温馨提示
试读
74页
Scripting InDesign CS3-4 with JavaScript 想用 javascript 控制 indesign ? 想使 Indesign 用起来更方便?学习必备。
资源推荐
资源详情
资源评论
O
’
REILLY
®
Short Cuts
Find more at shortcuts.oreilly.com
O’REILLY
®
Short Cuts
Scripting
InDesign
CS3/4 with
JavaScript
By Peter Kahrel
Copyright © 2009 O’Reilly Media, Inc.
ISBN: 978-0-596-80252-3
InDesign provides a powerful set
of tools for producing beautiful
documents. While you can certainly
do all your work by hand through
InDesign’s graphical interface, there
are many times when it’s much easier to
write a script. Once you’ve automated
a task, you can run it over the whole
document, ensuring consistency, or
just when you need it, simplifying and
speeding your layout process. All it
takes is a bit of JavaScript knowledge
and a willingness to explore InDesign’s
programming features.
Contents
Introduction �������������������������������������������������� 2
Hello World! ������������������������������������������������� 3
The ExtendScript Toolkit (ESTK) �������������� 5
InDesign’s Object Model ����������������������������� 8
The Object Model Viewer�������������������������� 15
JavaScript ��������������������������������������������������� 18
Catching Errors ����������������������������������������� 36
Running Scripts ������������������������������������������ 37
Working with Text�������������������������������������� 38
Working with Tabs ������������������������������������� 45
Find and Change ���������������������������������������� 47
Tables ����������������������������������������������������������� 58
Text Frames ������������������������������������������������ 66
Graphics ������������������������������������������������������ 71
Captions ������������������������������������������������������ 72
Resources ���������������������������������������������������� 73
O’REILLY
®
Short Cuts
Scripting InDesign CS3/4 with JavaScript 2
Introduction
Two things stand between the would-be scripter and an InDesign Javascript:
InDesign’s object model and JavaScript. Though both are complex, once a few
hurdles are overcome, anyone can start writing scripts fairly quickly. This PDF
hopes to show that numerous tedious tasks in InDesign can be automated with very
simple scripts of sometimes just one or two lines. These simple scripts can pave the
way to more complicated scripts. What you need most of all is determination.
To give just one short example, imagine this task: you have a document with
dozens of pages, and each page contains one or more text frames and one or more
graphics. All these page items are on the same layer, and you decide that the
document would be much easier to handle if the graphics were on a separate layer.
The task, then, consists of two steps: create a new layer and move all graphics
to this layer. Can you imagine doing this manually? Well, the following two-line
script does it for you in a couple of seconds:
myLayer = app.activeDocument.layers.add ({name: "pictures"});
app.activeDocument.rectangles.everyItem( ).itemLayer = myLayer;
The rst line creates a new layer with the name “pictures,” the second line moves
all graphics to that layer. You ask, “But how do I know that layers are added like
that,” and “How do I know that graphics are in an object ‘rectangle’?” Read on—
the purpose of this PDF is to show how to nd this out. Another aim is to show
that there are many very tedious and labor-intensive tasks in InDesign which can
be solved with surprisingly simple scripts. You might even begin to enjoy writing
scripts!
This book is intended for people who know InDesign fairly well but do not
necessarily know much about scripting/programming. Knowledge of InDesign is
necessary; after all, if you don’t know InDesign, there’s not much point trying to
script it. Knowledge of a programming language is not necessary (though it helps,
of course). I believe that anyone can learn how to write scripts up to a certain level.
You don’t have to be a mathematician in order to acquire some scripting skills.
Besides, creating JavaScripts for InDesign is not about computer science: it is
about making something work in InDesign.
The PDF is organized as follows. We begin with writing a short script, “Hello
world,” to show which steps are involved in creating a script, saving it, and
running it. This section is followed by a brief overview of the ExtendScript Toolkit
(ESTK), the environment in which you write scripts. We tackle here just what you
need to use it meaningfully. The section after that deals with InDesign’s object
O’REILLY
®
Short Cuts
Scripting InDesign CS3/4 with JavaScript 3
model, providing an outline and its general principles, and some illustration of
properties and methods. After that comes a JavaScript primer. This is not a full
JavaScript course but deals with the main elements of the language and gives some
examples to get you started. The last three sections turn to some specic areas
in which scripts are useful to ll some voids in InDesign. All of them essentially
handle text. The rst of these sections deals with a number of basic text-scripting
techniques. After that, there’s a section that goes into various aspects of nd and
change. I rst show how this can be scripted merely to automate InDesign’s Find/
Change dialog, then move on to show how Find can be used to script a exible
kerning editor. We then take a close look at tables. Though InDesign’s tables
are quite powerful, some features are missing and we’ll show how these can be
scripted. In the last section we turn to some aspects text frames.
InDesign’s implementation of JavaScript is cross-platform. A script that you write
on a Mac also works on a PC. The book, then, can be used both by Mac users and
PC users. I refer to keys using both Mac and PC names where relevant (Return/
Enter, Ctrl/Cmd, Alt/Opt).
All of the scripts in this book have been tried and tested, and should work as
advertised in both CS3 and CS 4. Nevertheless, before trying any script, even those
that seem simple and innocuous, always make a copy of your document or try
the script on a mock document. Never try out a script on an unsaved production
document: InDesign’s undo works very well, but you don’t want to put yourself at
its mercy.
Hello World!
Let’s write a very simple script, save it, and run it. Do as follows (the method
we’re about to describe is the quickest and easiest right now, if not the most
elegant—we’ll sort that out shortly).
• In InDesign, open the scripts panel (Window → Automation → Scripts), click
on the “User” folder to display the scripts there, then right-click on any script’s
name, and choose “Edit Script” from the yout (see Figure 1).
• InDesign’s script editor, the ExtendScript Toolkit (ESTK), is launched and the
script you selected is opened in it. The screenshot in Figure 2 shows the ESTK.
• Never mind what you see displayed: press Opt/Ctrl+A to select all text and press
Del to delete it.
• In the edit window, type the following line (see Figure 2):
alert (“Hello World!”);
O’REILLY
®
Short Cuts
Scripting InDesign CS3/4 with JavaScript 4
• Choose File → Save As to save the script le under a different name, say,
hello_world.jsx (you can use any name, but you must use the extension .jsx).
Figure 2.
Figure 1.
O’REILLY
®
Short Cuts
Scripting InDesign CS3/4 with JavaScript 5
• The script’s name will appear in InDesign’s Scripts panel. To run the script,
double-click its name. You should see an alert on your screen with the message
“Hello World!”; see Figure 3.
In the next section we turn to the ESTK in some more detail: we’ll show how to
start it as an independent application and how to run script directly from it.
The ExtendScript Toolkit (ESTK)
Scripts are plain text les that can be written in any text editor that can save les
as plain text (BBEdit, Notepad), but we’ll use the ESTK as it’s a dedicated editor
for writing JavaScripts and it comes free with InDesign. The ESTK can be started
as we did in the previous section, namely, by choosing to edit an existing script
in the Scripts panel. And indeed if you want to change an existing script, that’s a
convenient way.
But in the long run it’s easier to launch the ESTK as an independent application.
The application can be found in Program Files/Adobe/Adobe Utilities/ExtendScript
Toolkit CS4 (or, for CS3, in ExtendScript Toolkit 2). I have a shortcut to the
program (ExtendScript Toolkit.exe) on my desktop so I can launch it easily.
When saving a script, you can use any name, but you must use the extension .jsx.
Where to save your script depends on your operating system; see the box “Where
to Save Scripts” for details.
When the ESTK has launched you see it displayed on your screen as shown in
Figure 2. The layout of the different windows and panels will differ. We’ll not
go into great detail here; see Help → JavaScript Toolsguide CS4, chapter 2, for a
detailed introduction into the ESTK. Here, we’ll discuss just some basic features.
Like in InDesign, documents in the ESTK are displayed in the main window in
tabs with each document’s name displayed in the tab. The rst time you start the
ESTK, several panels are opened as well. For our purposes the most important
panel is the Console. This is the panel that you see in the top right in Figure 2
and is used by the ESTK to display various outputs of scripts that you run from
Figure 3.
剩余73页未读,继续阅读
资源评论
merrytoyou
- 粉丝: 0
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 3122080306 邹子轩 实验报告二.docx
- 基于STM32 NUCLEO板设计彩色LED照明灯(纯cubeMX开发)(大赛作品,文档完整,可直接运行)
- 发那科工业机器人保养大全
- Sphere.h
- REMD固有时间尺度分解信号分量可视化(Matlab完整源码和数据)
- 嵌入式系统双单片机STC89C52+STC15W104多功能学习板电路图可扩展 适用于单片机初学者和教学
- 基于STM32蓝牙控制小车系统设计(硬件+源代码+论文)大赛作品
- XILINXFPGA源码基于Spartan3火龙刀系列FPGA开发板VGA测试例程
- Java聊天室的设计与实现【尚学堂·百战程序员】
- python中matplotlib教程
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功