Is there anyway you can Debug varibles in AppleScript? have it print to output or the like?
Sure. The most common way is to add a line with display dialog yourVariable.
set theDemo to “abc”
display dialog theDemo
I will add display dialog at different points in the script and comment out the ones not being currently used for debugging.
Pressing the Cancel button will exit the script, pressing OK will continue the execution.
i never considered it untill after i asked but i might just be able to rig one up using the terminal too… but thank you
The display dialog technique will work with strings or numbers- Applescript coerces numbers to strings within context. Lists, which are a core type in AS, can be viewed in the Result window or you’ll need to set up a repeat loop to display each item.
Applescripts are compiled when run and therefore not readable outside Script Editor, Smile, or Script Debugger. I don’t believe you’ll be able to use Terminal for debugging purposes.
In addition to the above ‘display dialog’ and writing to file, you can also use the built-in ‘log’ command - pass it any AppleScript variable and it will log it in the Script Log window (assuming you’re not running as a standalone app):
set theFile to (choose file) log theFile
Beyond that, you can’t beat Script Debugger. It’s a full-featured script editor that includes the ability to step through your script, set breakpoints, see variables by just mousing over them, plus drag-and-drop variables from an application’s dictionary into your script. Well worth it if you’re ig into AppleScript.