Access to compile and runtime error feedback in Script Debugger so we can copy all the error feedback with just one command

I realise that work on SD will be no more, but just in case this is possible before stumps…

Using ChatGTP Co Copilot as training wheels (I know, I know, please don’t start!) it’s useful to copy and paste error messages back into ChatGTP as prompts.

That is more difficult in SD than would be ideal. For e.g. Compile errors appear in the bottom gutter of the current script window and the text cannot be highlighted to copy & paste it. if it is accessible elsewhere I’m yet to discover it.

in the case of runtime errors, I have to copy and paste 4 or 5 different bits of text that cannot be copied in one contextual menu command or {1. highlight all the error text , 2. Copy it (Cmd + C) 3. paste it into CHatGTP}

Currently I need to do this long routine of operationsL

  1. set Scope Bar to Source context
  2. contextual click in the Scope Bar, Menu> Copy Event,
  3. switch apps to ChatGTP
  • paste into prompt field
  • switch apps to Script Debugger
  • a contextual click in the Scope Bar, Menu> Copy Event Result
  • switch apps to ChatGTP
  • paste into prompt field

additionally I sometimes add the following steps if I think it might help ::

  • switch apps to Script Debugger
  • set Scope Bar to Raw context
  • contextual click in the Scope Bar, Menu> Copy Event,
  • switch apps to ChatGTP
  • paste into prompt field
  • switch apps to Script Debugger
  • a contextual click in the Scope Bar, Menu> Copy Event Result
  • switch apps to ChatGTP
  • paste into prompt field
  • switch apps to Script Debugger
  • set Scope Bar to AEPrint context
  • contextual click in the Scope Bar, Menu> Copy Event,
  • switch apps to ChatGTP
  • paste into prompt field
  • switch apps to Script Debugger
  • a contextual click in the Scope Bar, Menu> Copy Event Result
  • switch apps to ChatGTP
  • paste into prompt field

Because of the need to use contextual menu items to copy this text, I can’t even use LaunchBar’s double Cmd+C click to add the highlighted text to the existing text on the clipboard, which would allow for no more than one app switch and a single paste operation. So I have to switch apps back and forwards each time I copy some text then switch, paste and switch back to Script Debugger to get the next snippet of feedback text.

As you can imagine this is a PITA to do every time ChatGTP writes bad code (95% of the time there is at least one compile or runtime error in my limited experience).

It would be awesome to be able to able to copy the compile error text and all of the runtime error texts available visually in the UI but not easily copied in one fell swoop.

Now I think about it, I guess someone better than me + ChatGTP i0 could write an AppleScript to do just what I need!

Script Debugger’s scripting interface provides access to information about the last runtime error a script experienced:

  • last error application - Application of the script’s most recent runtime error, as displayed in the error dialog’s Application pane (or missing value if there was no application, or the script has compiled/run successfully).

  • last error expected type - Expected type of the script’s most recent runtime error, as displayed in the error dialog’s Expected Type pane (or missing value if there was no expected type, or the script has compiled/run successfully).

  • last error message - Text message of the script’s most recent compilation or runtime error (or missing value if the script has compiled/run successfully).

  • last error number - Numeric code of the script’s most recent compilation or runtime error (or missing value if the script has compiled/run successfully).

  • last error offending object - Offending object of the script’s most recent runtime error, as displayed in the error dialog’s Offending Object pane (or missing value if there was no offending object, or the script has compiled/run successfully).

  • last error partial result - Partial result of the script’s most recent runtime error, as displayed in the error dialog’s Partial Result pane (or missing value if there was no partial result, or the script has compiled/run successfully).

  • last error range - Content and position of the script’s most recent compilation or runtime error (or missing value if the script has compiled/run successfully).

    The last error range is effectively a selection within the script. If you ask for it as text (or nothing), you get the troublesome text. If you ask for it as a point, you get a list containing a pair of integers, the starting offset and the length of that text within the script. See the discussion of the selection-object class.

  • last result - The result produced by the script the last time it was run, or by the most recently executed line in debug mode (or missing value if the script has not been run).

These document properties may not provide all the information you need, but this is everything that AppleScript reports back to Script Debugger.

You can also use the document’s event log entry collection which gives you access to every AppleEvent your script sends along with the result or error the event generated.

1 Like

Thanks that should make it pretty easy to achieve what I’m looking for, It just occurred to me that most of my frustrations with the AS language are around Object Specifiers, and getting them wrong — at this point in my novice learnings. GTP has the very same issues I think. I’m drafting a post about that right now.

Thanks @alldritt

Is there any kind of REPL for AppleScript in Script Debugger or anywhere else that I can type single line AS into to return certain values such as these? Or I’ll always need to write a script for anything?

I tried making an expression in Script Debugger results panel for the script I wanted to get the latest message from. that didn’t work, probably I wasn’t referencing the parent objet but I have known idea what that should be.

perhaps I need to direct this to the Application Script Debugger and the other script window where the error is? I have no clue and am rediscovering why I loathed trying to learn AS in the past. the syntax and the hieroglyphic object specifiers are so obtuse to learn!

I was accessing the bounds of rectangles yesterday, today I cannot get a single page element to return its bounds. want to throw something, and it’s not another error. I realise that bounds is not a rectangle property and needs to be invoked from a spread or page element to get it to return a value list, but it’s still not there yet for me today. ugh.

Firstly, I suggest using nested tell blocks to build your references. This allows you to evaluate each part of the reference separately using the tools Script Debugger provides.

The Tell Context inspector shows the tell context, including all available properties and collections, that surrounds the text selection in your script. You can move up and town the object specifier and quickly see what you are referring.

And then the piece: you can select a contained object or property and use the Paste button to insert the AppleScript code that accesses this item.