Blocks

A block is a chunk of reusable JavaScript that performs some task. By dragging and dropping blocks into your scripts you can quickly assemble to code needed to perform a task. Blocks are also designed to try and work together to make things happen in your automation script.

Let's try and example of that now. Create a new script by clicking on the 'New' button in the Script Editor. This time choose the category 'General' and the template 'Create an empty script'. This will open up a new blank script. When the Script Editor starts up it presents you with a blank script automatically, so this step is usually not needed.

Now make sure the 'Blocks' tool window is showing by clicking on the 'Blocks' tab at the bottom of the tool pane. At the top you will now see a part of the tree called 'Files'. If you click on that it will expand to show you a list of the file type blocks defined on your computer. Click on the 'Get list of files in a folder' block and drag it over your blank script, and drop it. A (what should be familiar by now) template properties dialog will now be displayed asking you for the details needed to add this block. Click on the 'Folder' property then click on the ... button and choose a directory on your computer. Then click on 'OK'. A bunch of JavaScript was just added to your script. This script looks at the directory your chose and gets a list of all the files in it.

Look at the left margin of the script and you will see two things. First a gray square in the far left margin. This square will reactivate the block editor if you click on it. That allows you to make changes to blocks of code you have already defined, without editing the JavaScript itself. The second thing you will see is a bunch of minus signs. Those are "fold" points in the code. If you click on them you can fold up the JavaScript code so you won't have to look at it. Click on the minus sign next to the gray square at the top of the JavaScript you just added to your script. That folded up all the code that the block added. It is still there in the script but you no longer have to look at it. If you want to see the code again, click on the plus sign in the marges and it will unfold the code.

Now we have a list of files, let's do something with them. In the 'Blocks' window there is another group of blocks called 'Lists'. Open that collection of blocks. Now you should see a block called 'Display items in a list'. Click on that item and drag it into your script. Drop it below the JavaScript that is already there. There isn't anything we need to change for this block so just click on 'OK' when the 'Template Properties' dialog opens. Fold up that chunk of script as well and now we are ready to run our script. So click the 'Play' button.

You will be asked to save the script first and something else will happen. You are told that the script does not contain triggers and that without them its possible nothing will happen. You can ignore that for now. Save and run the script (see Running a Script) and an alert will pop-up with a list of files in it. Some of the files will probably not be displayed because alerts have a limit on the amount of information they can show.

This is the basics for building a script from blocks. You can also create new blocks, that you can later use in your scripts. To do this you would click on the 'Create' button on the menu bar at the top of the Script Editor. This will allow you to create new blocks that will be added to the block tool window.

Next Triggers