Skip to main content

Create a macro

Create a macro so page editors can insert your own block into Confluence pages. You write the code, check it on a page in the live preview, then turn it on.

Applies to: Script Master for Confluence Β· Cloud

Before you begin​

  • Confluence permission: Confluence admin. Only Confluence admins can open Script Master.
  • App permission: an active Script Master license. Without one, you can't create macros.
  • The site has fewer than 100 macros.

Open the editor​

  1. In Script Master, open the Macros tab. On a narrow window it can sit under More.

  2. Choose how to start:

    • Select Create macro for an empty editor.
    • Select the arrow next to Create macro (More ways to create) > From a template > Add labels.
    • Select the arrow > Import to paste a macro exported from another site. See Import, export and duplicate.

    Before the first macro, the tab shows Create macro, From a template and Import as separate buttons.

    The editor opens. A template fills in the title, description and code.

Fill in the macro​

  1. In Title, enter the name page editors see when they pick a macro. Up to 128 characters.

    The macro editor with Title and Description above the HTML Content code, and the preview showing the macro on a page

  2. In Description, say who the macro is for and how to use it, for example what to type in the macro body. Up to 256 characters.

  3. In HTML Content, write the macro's code. Put JavaScript in <script> tags. See Write fragment code, which applies to macros too.

All three fields are required.

Check it in the preview​

The preview beside the code runs the macro. Set what it runs against in the fields the preview shows, or later by selecting the pick at the left of its toolbar. To see the macro on a page, turn on Show Confluence's frame in Preview options (β€’β€’β€’):

FieldWhat it sets
SpaceThe space in the macro's context
PageThe page in the macro's context. Pick a space first, then search by title
Max heightA height cap in pixels, as an editor would set it. Leave it empty for none

The preview never passes a macro body. If your code reads context.extension.config.macroBody, it gets nothing here, so make the code handle that. See The macro body.

Writes in the preview wait until you select something inside it, and then they're real. See Preview your code.

Save and turn it on​

  1. Select Save, or press Ctrl+S (Cmd+S on a Mac). To add a note to this version, select the arrow next to Save > Save with note….
  2. Turn on Enable at the top of the editor.
  3. Select Save again.

Result: Script Master shows "Macro saved!" with the version number. Page editors can now pick it in Custom Macro. See Add a macro to a page.

Change or remove a macro​

In the Macros tab, select the macro's name to open it. Each row's β€’β€’β€’ menu also has Version history…, Turn on or Turn off, Duplicate, Export and Delete….

To delete a macro:

  1. In the macro's row, select β€’β€’β€’ > Delete….

  2. Select Delete to confirm.

    warning

    Deleting can't be undone. Pages that use the macro can no longer show it, and its failure record and version history go with it.

Result: The macro is gone from the list.

  • Macros: the macro body, context fields, and what pages show when a macro is off.
  • Preview your code: the status, the console and held writes.
  • Version history: compare and restore earlier versions.
  • Failures: what the list and editor show when a macro fails.