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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
|
<?xml version="1.0" encoding="UTF-8"?>
<helpdocument version="1.0">
<!--
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
-->
<meta>
<topic id="textsharedguidescriptingxml" indexer="include">
<title xml-lang="en-US" id="tit">Scripting %PRODUCTNAME</title>
<filename>/text/shared/guide/scripting.xhp</filename>
</topic>
</meta>
<body>
<bookmark xml-lang="en-US" branch="index" id="bm_id5277565"><bookmark_value>assigning scripts</bookmark_value>
<bookmark_value>programming;scripting</bookmark_value>
<bookmark_value>form controls;assigning macros</bookmark_value>
<bookmark_value>pictures;assigning macros</bookmark_value>
<bookmark_value>hyperlinks;assigning macros</bookmark_value>
<bookmark_value>shortcut keys;assigning macros</bookmark_value>
<bookmark_value>controls;assigning macros (Basic)</bookmark_value>
<bookmark_value>menus;assigning macros</bookmark_value>
<bookmark_value>events;assigning scripts</bookmark_value>
</bookmark><comment>MW deleted "programming;...", "scripting in programming", "BeanShell scripting", "Basic;..." and "java;..."</comment><comment>MW added "controls;..", "menus;..." and "events;..."</comment>
<paragraph xml-lang="en-US" id="par_idN1070A" role="heading" level="1"><variable id="scripting"><link href="text/shared/guide/scripting.xhp">Assigning Scripts in %PRODUCTNAME</link>
</variable></paragraph>
<paragraph xml-lang="en-US" id="par_idN10728" role="paragraph">You can assign custom scripts (macros) to menu items, icons, dialog controls, and events in %PRODUCTNAME.</paragraph>
<paragraph xml-lang="en-US" id="par_idN1072B" role="paragraph">%PRODUCTNAME internally supports the following scripting languages:</paragraph>
<list type="ordered">
<listitem>
<paragraph xml-lang="en-US" id="par_idN10731" role="paragraph">%PRODUCTNAME Basic</paragraph>
</listitem>
<listitem>
<paragraph xml-lang="en-US" id="par_idN10739" role="paragraph">JavaScript</paragraph>
</listitem>
<listitem>
<paragraph xml-lang="en-US" id="par_idN1073D" role="paragraph">BeanShell</paragraph>
</listitem>
<listitem>
<paragraph xml-lang="en-US" id="par_id6797082" role="paragraph">Python</paragraph>
</listitem>
</list>
<paragraph xml-lang="en-US" id="par_idN1091F" role="paragraph">In addition, developers can use high-level languages, for example Java programming language, to control %PRODUCTNAME externally. The API reference is online at <link href="https://api.libreoffice.org/" name="api.libreoffice.org">api.libreoffice.org</link>.</paragraph>
<paragraph xml-lang="en-US" id="par_idN10751" role="heading" level="2">To assign a script to a new menu entry</paragraph>
<list type="ordered">
<listitem>
<paragraph xml-lang="en-US" id="par_idN10758" role="paragraph">Choose <emph>Tools - Customize</emph>, and click the <emph>Menus</emph> tab.</paragraph>
</listitem>
<listitem>
<paragraph xml-lang="en-US" id="par_idN1093D" role="paragraph">Click <emph>Add</emph>.</paragraph>
</listitem>
<listitem>
<paragraph xml-lang="en-US" id="par_idN10760" role="paragraph">In the <emph>Category</emph> list box, scroll down and open the "Application Macros" entry.</paragraph>
</listitem>
<listitem>
<paragraph xml-lang="en-US" id="par_idN10768" role="paragraph">You see entries for "Application Macros" (scripts in the share directory of your %PRODUCTNAME installation), "My Macros" (scripts in the user directory), and the current document. Open any one of them to see the supported scripting languages.</paragraph>
</listitem>
<listitem>
<paragraph xml-lang="en-US" id="par_idN1076C" role="paragraph">Open any scripting language entry to see the available scripts. Select a script.</paragraph>
</listitem>
<listitem>
<paragraph xml-lang="en-US" id="par_idN10770" role="paragraph">A list of the script functions appears in the <emph>Commands</emph> list box. Select a function.</paragraph>
</listitem>
<listitem>
<paragraph xml-lang="en-US" id="par_idN10778" role="paragraph">Click <emph>Add</emph> to create a new menu assignment. The new menu entry appears in the <emph>Entries</emph> list box.</paragraph>
</listitem>
</list>
<paragraph xml-lang="en-US" id="par_idN10783" role="heading" level="2">To assign a script to a key combination</paragraph>
<list type="ordered">
<listitem>
<paragraph xml-lang="en-US" id="par_idN10787" role="paragraph">Choose <emph>Tools - Customize - Keyboard</emph>.</paragraph>
</listitem>
<listitem>
<paragraph xml-lang="en-US" id="par_idN10A59" role="paragraph">In the <emph>Category</emph> list box, scroll down and open the "Application Macros" entry.</paragraph>
</listitem>
<listitem>
<paragraph xml-lang="en-US" id="par_idN10A61" role="paragraph">You see entries for "Application Macros" (scripts in the share directory of your %PRODUCTNAME installation), "My Macros" (scripts in the user directory), and the current document. Open any one of them to see the supported scripting languages.</paragraph>
</listitem>
<listitem>
<paragraph xml-lang="en-US" id="par_idN10A65" role="paragraph">Open any scripting language entry to see the available scripts. Select any script.</paragraph>
</listitem>
<listitem>
<paragraph xml-lang="en-US" id="par_idN10A69" role="paragraph">A list of the script functions will appear in the <emph>Commands</emph> list box. Select any function.</paragraph>
</listitem>
<listitem>
<paragraph xml-lang="en-US" id="par_idN10A71" role="paragraph">Click the option button for %PRODUCTNAME or Writer (or whichever application is currently open). </paragraph>
<paragraph xml-lang="en-US" id="par_idN10A74" role="paragraph">Selecting the option button sets the scope of the new key combination to be applicable in all of %PRODUCTNAME or only in documents of the current module.</paragraph>
</listitem>
<listitem>
<paragraph xml-lang="en-US" id="par_idN10A78" role="paragraph">Select a key combination from the <emph>Shortcut keys</emph> list box and click <emph>Modify</emph>.</paragraph>
</listitem>
</list>
<paragraph xml-lang="en-US" id="par_idN1078A" role="heading" level="2">To assign a script to an event</paragraph>
<list type="ordered">
<listitem>
<paragraph xml-lang="en-US" id="par_idN1078E" role="paragraph">Choose <emph>Tools - Customize - Events</emph>.</paragraph>
</listitem>
<listitem>
<paragraph xml-lang="en-US" id="par_idN10A16" role="paragraph">Click <emph>Macro</emph> button.</paragraph>
</listitem>
<listitem>
<paragraph xml-lang="en-US" id="par_idN10A9E" role="paragraph">In the <emph>Library</emph> list box, scroll down and open the "Application Macros" entry.</paragraph>
</listitem>
<listitem>
<paragraph xml-lang="en-US" id="par_idN10AA6" role="paragraph">You see entries for "Application Macros" (scripts in the share directory of your %PRODUCTNAME installation), "My Macros" (scripts in the user directory), and the current document. Open any one of them to see the supported scripting languages.</paragraph>
</listitem>
<listitem>
<paragraph xml-lang="en-US" id="par_idN10AAA" role="paragraph">Open any scripting language entry to see the available scripts. Select any script.</paragraph>
</listitem>
<listitem>
<paragraph xml-lang="en-US" id="par_idN10AAE" role="paragraph">A list of the script functions will appear in the <emph>Assigned Action</emph> list box. Select any function.</paragraph>
</listitem>
<listitem>
<paragraph xml-lang="en-US" id="par_idN10AB6" role="paragraph">Select to save in %PRODUCTNAME or current document.</paragraph>
<paragraph xml-lang="en-US" id="par_idN10AB9" role="paragraph">This sets the scope of the new event assignment to be applicable in all of %PRODUCTNAME or only in documents of the current module.</paragraph>
</listitem>
<listitem>
<paragraph xml-lang="en-US" id="par_idN10ABD" role="paragraph">Select an event from the list and click <emph>OK</emph>.</paragraph>
</listitem>
</list>
<paragraph xml-lang="en-US" id="par_idN10791" role="heading" level="2">To assign a script to an event for an embedded object</paragraph>
<list type="ordered">
<listitem>
<paragraph xml-lang="en-US" id="par_idN10795" role="paragraph">Select the embedded object, for example a chart, in your document.</paragraph>
</listitem>
<listitem>
<paragraph xml-lang="en-US" id="par_idN10ADB" role="paragraph">Choose <emph>Format - Frame and Object - Properties - Macro</emph>.</paragraph>
</listitem>
<listitem>
<paragraph xml-lang="en-US" id="par_idN10ADF" role="paragraph">In the <emph>Macros</emph> list box, open the %PRODUCTNAME Scripts entry.</paragraph>
</listitem>
<listitem>
<paragraph xml-lang="en-US" id="par_idN10AE7" role="paragraph">You see entries for share (scripts in the share directory of your %PRODUCTNAME installation), user (scripts in the user directory), and the current document. Open any one of them to see the supported scripting languages.</paragraph>
</listitem>
<listitem>
<paragraph xml-lang="en-US" id="par_idN10AEB" role="paragraph">Open any scripting language entry to see the available scripts. Select any script.</paragraph>
</listitem>
<listitem>
<paragraph xml-lang="en-US" id="par_idN10AEF" role="paragraph">A list of the script functions will appear in the <emph>Existing macros in</emph> list box. Select any function.</paragraph>
</listitem>
<listitem>
<paragraph xml-lang="en-US" id="par_idN10AF7" role="paragraph">Select an event from the list and click <emph>OK</emph>.</paragraph>
</listitem>
</list>
<paragraph xml-lang="en-US" id="par_idN10798" role="heading" level="2">To assign a script to a hyperlink</paragraph>
<list type="ordered">
<listitem>
<paragraph xml-lang="en-US" id="par_idN1079C" role="paragraph">Position the cursor inside the hyperlink. </paragraph>
</listitem>
<listitem>
<paragraph xml-lang="en-US" id="par_idN10B15" role="paragraph">Choose <emph>Insert - Hyperlink</emph>.</paragraph>
</listitem>
<listitem>
<paragraph xml-lang="en-US" id="par_idN10B19" role="paragraph">Click the <emph>Events</emph> button.</paragraph>
</listitem>
<listitem>
<paragraph xml-lang="en-US" id="par_idN10B21" role="paragraph">Select and assign as stated above.</paragraph>
</listitem>
</list>
<paragraph xml-lang="en-US" id="par_idN1079F" role="heading" level="2">To assign a script to a graphic</paragraph>
<list type="ordered">
<listitem>
<paragraph xml-lang="en-US" id="par_idN107A3" role="paragraph">Select the graphic in your document. </paragraph>
</listitem>
<listitem>
<paragraph xml-lang="en-US" id="par_idN10B3B" role="paragraph">Choose <emph>Format - Image - Properties - Macro</emph>.</paragraph>
</listitem>
<listitem>
<paragraph xml-lang="en-US" id="par_idN10B3F" role="paragraph">Select and assign as stated above.</paragraph>
</listitem>
</list>
<paragraph xml-lang="en-US" id="par_idN107A6" role="heading" level="2">To assign a script to a form control</paragraph>
<list type="ordered">
<listitem>
<paragraph xml-lang="en-US" id="par_idN107AA" role="paragraph">Insert a form control, for example a button: Open the Form Controls toolbar, click the <emph>Push Button</emph> icon, drag open a button on your document.</paragraph>
</listitem>
<listitem>
<paragraph xml-lang="en-US" id="par_idN10B59" role="paragraph">With the form control selected, click <emph>Control</emph> on the Form Controls toolbar.</paragraph>
</listitem>
<listitem>
<paragraph xml-lang="en-US" id="par_idN10B5D" role="paragraph">Click the <emph>Events</emph> tab of the Properties dialog.</paragraph>
</listitem>
<listitem>
<paragraph xml-lang="en-US" id="par_idN10B61" role="paragraph">Click one of the <emph>...</emph> buttons to open a dialog where you can assign a script to the selected event.</paragraph>
</listitem>
</list>
<paragraph xml-lang="en-US" id="par_idN107AD" role="heading" level="2">To assign a script to a control in the %PRODUCTNAME Basic dialog</paragraph>
<list type="ordered">
<listitem>
<paragraph xml-lang="en-US" id="par_idN107B1" role="paragraph">Open the %PRODUCTNAME Basic dialog editor, then create a dialog with a control on it.</paragraph>
</listitem>
<listitem>
<paragraph xml-lang="en-US" id="par_idN10B7F" role="paragraph">Right-click the control, then choose <emph>Properties</emph>.</paragraph>
</listitem>
<listitem>
<paragraph xml-lang="en-US" id="par_idN10B87" role="paragraph">Click the <emph>Events</emph> tab of the Properties dialog.</paragraph>
</listitem>
<listitem>
<paragraph xml-lang="en-US" id="par_idN10B8B" role="paragraph">Click one of the <emph>...</emph> buttons to open a dialog where you can assign a script to the selected event.</paragraph>
</listitem>
</list>
</body>
</helpdocument>
|