Trouble with AppleScript Handler Returning Values in Script Debugger

Hi everyone,

I’ve been working on a project in Script Debugger where I’m trying to use a handler to return a value, but I’m running into some issues. The goal is for the handler to process some data and return it for further use in my script, but it seems like the value is either not being returned properly, or I’m missing something with how to capture it.

Here’s a simplified version of the script I’m working on:

on processText(theText)
set processedText to "Processed: " & theText
return processedText

end processText

set myText to "Hello, world!"
set resultText to processText(myText)
display dialog resultText

I expected the handler to return “Processed: Hello, world!” and display that in the dialog box, but for some reason, I keep getting an empty dialog or a different error altogether.

I have not found any solution. Could anyone guide me about this? I have tried running this in both Script Editor and Script Debugger, and while Script Editor sometimes works (though not always), Script Debugger seems to have consistent issues with returning the value from the handler.

Has anyone else encountered something similar when working with handlers and returning values in Script Debugger?

Thanks in advance!

Respected community member! :smiling_face_with_three_hearts:

That works fine here. Perhaps you’ve over-simplified?

Works here too.

→ Mac OS: 14.6.1 (23G93)
→ Script Debugger 8.0.8 (8A80)

Have you declared dependencies at the top of your script, like this? It’s required.

use AppleScript version "2.4" --	Yosemite or later
use scripting additions

There are more options for the AS version, though version 2.4 is usually sufficient.

use AppleScript version "2.8" --	Ventura, Sonoma or later
use AppleScript version "2.7" --	High Sierra, Mojave, Catalina, Big Sur or later
use AppleScript version "2.5" --	El Capitan, Sierra or later

BTW, does anyone know whether Sequoia includes a new version of AS?

Alas, not until you post the actual code that’s failing.