Creating a Modal Window Progress Bar
By Steven H. Blackwell (steven_blackwell@csgi.com)

BONUS FILE: PBAR.FP3
(REQUIRES Jon's Commands & Dialog Director)
PLATFORM: Macintosh Only

If you have ever wanted to create a true modal window progress bar in a FileMaker solution, here is one way to do that using an embedded AppleScript in FileMaker. The accompanying demonstration file, PBar.fp3, has the finished product.

In these scripts are several special characters. The line break or continuation character ¬ is created by the option_key+l (lowercase L). The chevrons surrounding some event names « and » are created by the option_key + pipe_key (|) and shift_key + option_key + pipe_key, respectively. The pipe_key is usually found immediately below the delete_key at the right end of the QWERTY row on the keyboard. These symbols are not created by the character keys on the bottom row.

This script requires the use of two Open Scripting Architecture Extensions (OSAX) found on the Everything Scripting for Macintosh, Volume I CD published by ISO <www.everythingcd.com>. The DialogDirector OSAX extends the functionality of the script. Jon's Commands OSAX controls some of the timing requirements. This script also requires Macintosh OS 8.1 or 8.5.1 and FileMaker Pro For Macintosh 4.0v2 or 4.1v1. It may run on another OS as well, but I recommend these. To install the scripting additions, simply drag them to your System Folder and the MacOS will place them in the Scripting Additions folder within the Extensions folder for you. {For experienced scripters, please note that the elements of Jon's Commands folded into the Standard Additions OSAX in OS 8.5.1 do not include the properties required for this script; hence Jon's Commands is still needed.}

Create a ScriptMaker script in FileMaker with a single step "Perform AppleScript". In the example file is a global text field called "Script Text". Have the AppleScript call that field's value as the script text. You could, of course, hardwire the script text into the Perform AppleScript step, but with the global field the script is easier to see and study.

Here is the text of the script with comments and explanations following:

property theMax : 10000
property waitticks : 10

dd install with greyscale

set p to dd make dialog {size:[300, 50], contents:[¬
{class:gauge, bounds:[10, 25, 290, 25 + 12], «class pVAL»:0, max value:theMax}, ¬
{class:static text, bounds:[120, 4, 288, 20], contents:"", justification:right}]}
set n to 1
set x to 1

repeat while n < theMax
dd set value of item 1 of p to n
set startticks to the ticks
repeat
    if (the ticks) > waitticks + startticks then
        exit repeat
    end if
end repeat
set n to n + x
set x to x + 1
if x mod 50 = 0 then dd set contents of item 2 of p to "I'm working, OK?"
if x mod 100 = 0 then dd set contents of item 2 of p to "When I'm Through!"
end repeat
beep
dd delete p
dd uninstall

Here is how the script works. Note the commands "dd install with greyscale" and "dd uninstall" at the beginning and end of the script. These are used specifically to call the parameters associated with the DialogDirector OSAX.

The first thing to do is to assign values to some variables needed in the script. Hence the two lines:

property theMax : 10000
property waitticks : 10

that assign values to variables "theMax" and "waitticks". The first of these determines for how long the Progress Bar runs; the second controls its speed.

Now, we make the physical appearance of the modal dialog box holding the progress bar itself with this portion of the script:

{size:[300, 50], contents:[¬
{class:gauge, bounds:[10, 25, 290, 25 + 12], «class pVAL»:0, max value:theMax}, ¬
{class:static text, bounds:[120, 4, 288, 20], contents:"", justification:right}]}

Note the properties of the dialog: "size" and "contents" which has the following properties itself. A "gauge" (the progress bar) with specific "bounds", an initial value («class pVal»), a "max value" as defined before, and some "static text" which appears as a message while the progress bar runs. That "static text" has "bounds", an initial "contents" of empty, and a right justification.

The next part of the script makes the progress bar run:

set n to 1
set x to 1

repeat while n < theMax
dd set value of item 1 of p to n
set startticks to the ticks
repeat
    if (the ticks) > waitticks + startticks then
        exit repeat
    end if
end repeat
set n to n + x
set x to x + 1

Setting the values "n" and "x" each to equal 1 gives them their initial values. The «repeat while» event simply calls the script and increments the value of "n" until such time as the value equals theMax value we assigned at the start.

The part of the script regarding startticks and waitticks controls the speed of the progress bar's movement by inducing slight waits. There are 60 ticks per second, so a waittick time of 10 ticks is one-sixth of a second. That's not a lot of time, but enough for persistence of vision to see the bar's moving. {For experienced scripters, in OS 8.5.1, the «delay» event could be used, but it is apparently restricted to seconds, not ticks.}

The following part of the script determines what message will display as the progress bar moves across the screen and when those messages display:

if x mod 50 = 0 then dd set contents of item 2 of p to "I'm working, OK?"
if x mod 100 = 0 then dd set contents of item 2 of p to "When I'm Through!"

As soon as the value of "x" hits 50 the first message appears; when it hits 100, the second one appears.

The final part of the script ends the repeat and performs cleanup of the progress bar:

end repeat
beep
dd delete p
dd uninstall

And that's one way, of many ways to be sure, that a modal dialog progress bar can be inserted in a FileMaker solution. Developers can use this to enhance and improve the appearance of their solutions and to provide information to users to let them know that activity is occurring in the file.

An article in issue #32 of the ISO FileMaker magazine demonstrates how to create progress bars within FileMaker Pro without using AppleScript. Why would you want to use this solution? The simple answer is quality. Compare the progress bar from this solution to the progress bar in issue #32 and you will see a marked difference. The progress bar from issue #32 flashes a lot more. Maybe this is okay for some solutions. However, if you know your solution will not be used on the Windows platform, a more professional looking progress bar may be possible. In addition, Troi has a plug-in that creates very nice looking progress bars <www.troi.com>. Consider all of these options when deciding on a solution. Pick the one that meets your needs best.

## END ##