How to debug a Folder Action Script

Hi everybody.

I´m writing a script about adding items to my downloads folder to automate a workflow.
The script is located at the Folder Action Scripts folder insider the Library folder of the disk, and It is attached to the downloads folder and “it works”.

What happens is that I have difficult problems to debug it because when the script runs I can´t see where´s the problem in Script Debugger. I mean, I can put dozens of “display notification” to find out where the problem is but maybe there is another better way to debug it.
How could I debug it?

Maybe it is a very simple question but I´m very new with this software and with AppleScript.

Thanks for your time

Script Debugger gives you two options:

  1. Simulation

    Within Script Debugger, you can open your script, enable debugging, set breakpoints at key locations, and then use one of the Folder Actions options from the Execute/Step Over/Step Into submenus:

    NOTE: the various Folder Actions menu items are enabled when Script Debugger sees that your script defines handlers for these events.

    Selecting one of these menu items allows you to invoke a particular Folder Actions handler with parameters you choose to simulate the Folder Actions environment. This is probably best approach for most debugging.

  2. External Debugging

    Within Script Debugger, open your script, enable debugging, set breakpoints, and save your script. With the script remaining open in Script Debugger, configure Folder Actions to invoke your script. Then, drop files on your folder, delete files from your folder, etc. to cause Folder Actions to invoke your script.

    Each time you do anything to trigger Folder Actions, Script Debugger will appear and allows you to step through your code. The key is to have breakpoints set at key locations so that Script Debugger can pause at useful points in your code.

    NOTE: It is important that you disable debugging and resave your script when you are finished debugging. Failing to do this will cause Script Debugger to continue appearing each time your script is invoked by Folder Actions.

4 Likes