תוכן
\<bookmark_value\>assigning scripts\</bookmark_value\>\<bookmark_value\>Basic;scripting\</bookmark_value\>\<bookmark_value\>BeanShell scripting\</bookmark_value\>\<bookmark_value\>Java;scripting\</bookmark_value\>\<bookmark_value\>programming;scripting\</bookmark_value\>\<bookmark_value\>scripting in programming\</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\>

# Assigning Scripts in LibreOffice

You can assign custom scripts (macros) to menu items, icons, dialog controls, and events in LibreOffice.

LibreOffice internally supports the following scripting languages:

1. LibreOffice Basic

2. JavaScript

3. BeanShell

4. Python

In addition, developers can use high-level languages, for example Java programming language, to control LibreOffice externally. The API reference is online at api.libreoffice.org.

## To assign a script to a new menu entry

1. Choose \<emph\>Tools - Customize\</emph\>, and click the \<emph\>Menus\</emph\> tab.

2. Click \<emph\>Add\</emph\>.

3. In the Category list box, scroll down and open the "Application Macros" entry.

4. You see entries for "Application Macros" (scripts in the share directory of your LibreOffice installation), "My Macros" (scripts in the user directory), and the current document. Open any one of them to see the supported scripting languages.

5. Open any scripting language entry to see the available scripts. Select a script.

6. A list of the script functions appears in the \<emph\>Functions\</emph\> list box. Select a function.

7. Click \<emph\>New\</emph\> to create a new menu assignment. The new menu entry appears in the \<emph\>Menu entries\</emph\> list box. Click the menu entry and enter text to rename the entry.

## To assign a script to a key combination

1. Choose \<emph\>Tools - Customize - Keyboard\</emph\>.

2. In the Category list box, scroll down and open the "Application Macros" entry.

3. You see entries for "Application Macros" (scripts in the share directory of your LibreOffice installation), "My Macros" (scripts in the user directory), and the current document. Open any one of them to see the supported scripting languages.

4. Open any scripting language entry to see the available scripts. Select any script.

5. A list of the script functions will appear in the \<emph\>Functions\</emph\> list box. Select any function.

6. Click the option button for LibreOffice or Writer (or whichever application is currently open).

   Selecting the option button sets the scope of the new key combination to be applicable in all of LibreOffice or only in documents of the current module.

7. Select a key combination from the Shortcut keys list box and click Assign.

## To assign a script to an event

1. Choose \<emph\>Tools - Customize - Events\</emph\>.

2. Click \<emph\>Assign Macro\</emph\>.

3. In the Library list box, scroll down and open the "Application Macros" entry.

4. You see entries for "Application Macros" (scripts in the share directory of your LibreOffice installation), "My Macros" (scripts in the user directory), and the current document. Open any one of them to see the supported scripting languages.

5. Open any scripting language entry to see the available scripts. Select any script.

6. A list of the script functions will appear in the \<emph\>Assigned Macros\</emph\> list box. Select any function.

7. Select to save in LibreOffice or current document.

   This sets the scope of the new event assignment to be applicable in all of LibreOffice or only in documents of the current module.

8. Select an event from the list and click \<emph\>Assign\</emph\>.

## To assign a script to an event for an embedded object

1. Select the embedded object, for example a chart, in your document.

2. Choose Format - Frame and Object - Properties - Macro.

3. In the \<emph\>Macros\</emph\> list box, open the LibreOffice Scripts entry.

4. You see entries for share (scripts in the share directory of your LibreOffice installation), user (scripts in the user directory), and the current document. Open any one of them to see the supported scripting languages.

5. Open any scripting language entry to see the available scripts. Select any script.

6. A list of the script functions will appear in the \<emph\>Existing macros in\</emph\> list box. Select any function.

7. Select an event from the list and click \<emph\>Assign\</emph\>.

## To assign a script to a hyperlink

1. Position the cursor inside the hyperlink.

2. Choose \<emph\>Insert - Hyperlink\</emph\>.

3. Click the \<emph\>Events\</emph\> button.

4. Select and assign as stated above.

## To assign a script to a graphic

1. Select the graphic in your document.

2. Choose Format - Image - Properties - Macro.

3. Select and assign as stated above.

## To assign a script to a form control

1. 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.

2. With the form control selected, click \<emph\>Control\</emph\> on the Form Controls toolbar.

3. Click the \<emph\>Events\</emph\> tab of the Properties dialog.

4. Click one of the \<emph\>...\</emph\> buttons to open a dialog where you can assign a script to the selected event.

## To assign a script to a control in the LibreOffice Basic dialog

1. Open the LibreOffice Basic dialog editor, then create a dialog with a control on it.

2. Right-click the control, then choose \<emph\>Properties\</emph\>.

3. Click the \<emph\>Events\</emph\> tab of the Properties dialog.

4. Click one of the \<emph\>...\</emph\> buttons to open a dialog where you can assign a script to the selected event.