Running Scripts
At this point you're probably starting to see how scripts could be really useful in your database. The fact is, most large database systems are loaded with scripts that do all kinds of things. But the only way you've seen to run a script is pretty tedious: Chose Scripts
13.3.1. The Scripts Menu
You can choose to show some or all of your scripts right in the Scripts menu. If you have a script or two that you want quick access to from anywhere, then it makes sense to put it in the Scripts menu. That way, anyone can run it by simply choosing it from the menu. There are even keyboard shortcuts for the first 10 scripts in the Scripts menu: Ctrl+1 (
|
13.3.2. Buttons
Throwing lots of scripts into the Scripts menu is a good way to give your users access to them no matter what context they're in. But what if you want to make a script available only on certain layouts? For scripts that apply only to the Invoices layout (like…oh…the Find Unpaid Invoices script), consider using buttons instead. When you add a button to the layout, FileMaker shows you the same Specify Button window you saw back on Section 6.6.5.3. Perform Script is the very first command available in the list (aside from Do Nothing). You can see the options associated with this button in Figure 13-9.
|
Using buttons, you can add one-click access to as many scripts as you want and you can place them where you want them. For example, you can put Invoice-related scripts on the Invoices layout and Payment-related scripts on the Payment layout. If you make sure your context-dependent scripts don't show up in the Scripts menu, you're adding another layer of assurance that FileMaker runs your scripts only from the right context.
Tip: If you want the ultimate in control over which of people get to see which scripts, and even which layout they can see them in, take a look at the Custom Menus section in Chapter 19. You need FileMaker Pro Advanced to create Custom Menus, but for many situations, this powerful feature alone is worth the price of admission.
13.3.3. Opening and Closing Scripts
Finally, you can tell FileMaker to automatically run a script when someone opens or closes the file. The opening script runs when you first open the file. You might use this script if you want to be greeted with the list of unpaid invoices first thing every morning. The closing script runs when you close the last window for an open file. This option is a little less common, but it has its uses: If you want to make sure other related files close whenever the main file closes (even if they have open windows), then you could write a script to close them all whenever you close the main file.
To make the selection, you need to visit the File Options dialog box (File
|