Script examples

This page shows some short examples of the most important functions provided by the built-in scripting language.

Copy/Paste the examples into an action Script and use Menu->Execute to test the action. The output will be written to the Automagic Log accessible with Menu->Log.

String operations

Test if a variable contains a value (exactly)

Test if a variable partly contains a specific text

Test if a string matches a regular expression (see Regular expressions)

Find the content of the groups in a regular expression

Create a list of lines from a multiline text

Create a list of words

Extract the contents of an HTML element

Modify a phone number from 00411234567 to 0 0 4 1 1 2 3 4 5 6 7 for better text to speech output

Test if a file name ends with the suffix .mp3

Strip off the file extension

Convert a text to upper case

Remove whitespace around a text

Replace variables in a string literal

Date & Time

Get and format the current date + time (see Date Format Pattern)

Create a specific date

Duration between two dates

Get the date from a text value and reformat

Modifying a date

Lists

Creating lists

Adding elements to a list

Sorting the values in a list

Reversing the values in a list

Finding the index of an element

Remove an element at a specific index

Inserting an element into the list

Test if an element is in the list

Adding an element if it is not in the list yet

Removing value "c" from the list

Testing the number of elements in a list

Adding an element to the list but keeping the list 4 element long

Looping over the elements of a list

Maps

Creating an empty map

Adding key/value-pairs to a map

overwriting an entry

Accessing the value for a key

get a list of all keys and values in map

XML

The examples in this section use the following input XML (in variable input):
<books>
    <book>
        <title>Book 1</title>
        <price>12.50</price>
        <pages format="A4">745</pages>
    </book>
    <book>
        <title>Book 2</title>
        <price>35.70</price>
        <pages format="A5">120</pages>
    </book>
    <book>
        <title>Book 3</title>
        <price>17.90</price>
        <pages format="letter">1230</pages>
    </book>
</books>

Extract book titles

Extract the price of the books

Print the format of Book 1

Print Book title of book with page format A5

Number theory

RSA (uses experimental functions)

Diffie Hellman (uses experimental functions)