Variable scope problem [bug?]

Hi All

I’m relatively new to AppleScript but have been coding for a long time so bring certain assumptions from other languages. Please take a look at the attached screenshot. I have encountered this issue quite a lot so am increasingly starting to think it must be a bug rather than my poor programming. “srcFolderName” should be visible. In fact, it is visible because it was successfully used in the “pathExists” function call on the line above. Why is it not listed in the variable pane, nor valid in the watch/expression pane?

Welcome to the party!

Short answer: Add this to the top of the script or handler where the variable is used:

local srcFolderName

Long answer: The variable viewer in ScriptDebugger only shows properties, globals and current declared local variables.

With AppleScript you don’t need to declare local variables the way you do with Properties or globals (outside of the implicit run handler).

But if you don’t declare a local variable, script debugger can’t show you it’s value.

HTH

2 Likes