If you are running into a situation where you seem to be coding the same routines over and over again, you can create a script file with reusable handlers, called script libraries.
Script Library files can technically be located anywhere, but it is strongly advisable to put them in their expected location: ~/Library/Script Libraries. If they are in this location, they can easily be called by name, not requiring the full path to be provided.
A script library contains handlers (the same as functions) that can be called from an external script.
Here is a simple example with a parameterized handler:
Now here is a simple script that calls the script library, setting it to a variable for ease of use.
Note how the handler can be called in the standard “handler of script” or the possessive form, “script’s handler”.
And the results…
And yes, a script library can easily contain multiple handlers.