Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I debug AppleScript?

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?

like image 697
Daryl Spitzer Avatar asked Sep 23 '09 14:09

Daryl Spitzer


People also ask

Does Apple still support AppleScript?

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).

How do I open AppleScript Editor?

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.

Why is AppleScript so slow?

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.


2 Answers

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 
like image 108
tuomassalo Avatar answered Oct 22 '22 08:10

tuomassalo


  1. Script Debugger
  2. XCode
  3. 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 
  4. 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 
like image 36
McUsr Avatar answered Oct 22 '22 07:10

McUsr