What tips and tricks do you have for debugging AppleScript? Is there a debugger? If not, what is the best way to insert "prints" to display the value of variables? Is there a way to "pretty print" more complicated data structures?
However, iOS and iPadOS have no support for AppleScript, and Apple is clearly heading in a trend of switching many apps over to Catalyst (and strongly encouraging 3rd party apps to do the same).
You can find it in the Utilities folder inside the Applications folder. You can also use Spotlight to search for “Script Editor” and open it that way. You can learn more about using the Script Editor here.
Having too many scripting additions slows AppleScript's load time, since it must process that many more files in the Scripting Additions folder. Also, more scripting additions means more event and class names must be parsed from 'aete' resources and added to the AppleScript symbol table.
The latest versions of xcode will let you create an AppleScript application but breakpoints in applescript don't work since Apple has discontinued support for AppleScript debugging in xcode.
Fallback: for simple "printf style" debugging you could use:
display dialog "my variable: " & myVar
Getting the properties of an object (see below) to understand why it fails, when run from script editor. You can also use the class word, to see what class a property is. The Dictionary for an app is a good starting point.
One technique that often would have helped me, (and that I still sometimes do) is to tell something to return their properties, like this:
tell application "TextEdit" get properties end tell
Log statements and Console.app, for debugging of runtime events. (further below). You can ofcourse turn debugging on and off by setting a property
Below is a techniuqe I use for tracking runtime errors, in applets, mail rules, and what have you. When it fails, the error number and message is logged into TestDrive.log, and can be found in the left margin of Console.app…
tell application "TextEdit" try set a to text 0 of its name on error e number n my logit("OOPs: " & e & " " & n, "TestDrive") end try end tell to logit(log_string, log_file) do shell script ¬ "echo `date '+%Y-%m-%d %T: '`\"" & log_string & ¬ "\" >> $HOME/Library/Logs/" & log_file & ".log" end logit
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With