r/applescript • u/JapanDave • Dec 14 '22
Calling other Applescript files from within a script?
I have a project where my core Applescript file is just getting huge. It is a pain to find the exact function I need sometimes. For organizational purposes, dividing this one file into several might help me keep my sanity. Can I make multiple files and then call functions within them from the main file?
I haven't programmed in years, but I seem to remember in C++ we would use an #include statement at the beginning to add functions from other files. Does Apple script have anything like this?
2
Upvotes
7
u/[deleted] Dec 14 '22
Looks like you need to start learning script objects and script libraries
4
u/copperdomebodha Dec 14 '22
Your plan to offload some of your code to a library is sound, but I feel like what you might really find useful is Script Debugger. All handlers are available in a pull-down menu so accessing one of hundreds in a long script is painless. And the debugging features make it well worth the price. There's a free, full-featured 20 day trial period to boot!
2
u/markconwaymunro Dec 14 '22
In addition to script libraries which can be included at the top of a script, you can load script filePath into a variable and then run the script or call any subroutine inside.
My 2010 AppleScript book outlines how to build a modular AppleScript solution.