Trouble loading code from my personal applescript file

I’m not sure if this is a debugger question or just a newbie not knowing his way around, but I thought I’d put this here and see what happens.
I have two scripts, one called “RC_applescript.scpt” which contains this code:

property rclibx : 5

The second script is called “evernote.scpt” and contains this code:

set rclib to load script file ((path to home folder as string) & "RC_applescript:RC_applescript.scpt")
tell rclib
	set its rclibx to (its rclibx) + 7
end tell

When I run evernote.scpt, it gives this error in the debugger:
Can’t get rclibx of «data scpt4D617259332E3030000blah blahEDEAD».

what is going on? The library loads but I can’t access anything in it…

It’s hard to say what’s happening — your code works fine here:

set rclib to load script file ((path to desktop as string) & "Testing.scpt")
tell rclib
	set its rclibx to (its rclibx) + 7
	set x to its rclibx
end tell
return x
--> 12

Solved in the other forum, thanks for your help and advice! What was causing this is that I saved “RC_Applescript.scpt” while viewing it in debugger mode. Apparently this leaves the file in some sort odd state that causes it to be loaded improperly. The solution is that I must NOT save the library (source) file containing the script to be loaded before taking the file out of debugger mode. Clear as mud?
Cheers

I would be curious to know why the file cares that it was being debugged. I would not expect a debugger to modify source files like that. At what point are changes made to the file and why?

AppleScript doesn’t support debugging, so Script Debugger has to provide its own debugging OSA component. When you save a script with debugging on, it is saved compiled against that component, not normal AppleScript.

Makes a lot of sense. Thanks for explaining. The idea of a compiled script is interesting. Seems like they should put all the debugging stuff after the end of the normal file somehow, even have a separate bundled thing as part of a script file couldn’t they? Oh well now I know, which is great, and I can do useful things more later. I already finished my intended little project but I won’t forget my lesson here.

Shane and Mark @alldritt,

I guess this begs the question: Is there a real need to save the script in debug format?
What is the purpose?
If/when the user opens the file later, it is easy enough to turn debugging.

This feature has also bit me a number of times, even though I knew about it.
I write a lot of scripts that are run from Keyboard Maestro, and sometimes after debugging, I have to quickly do something else, so I just save and quit SD.
Well, you know what happens from there. . .

Thanks for considering to quit saving the file in debug format.

Before many of the recent security changes, the debug format was very useful. For example, in the old days you could save a script with a mail handler, and then when it was triggered within Mail the script would open in Script Debugger so you could step through it “live”. Sadly, security changes have rendered it less useful.

However, because it involves compiling with a different component, saving with debugging off would mean a separate non-debug compile, which can be time-consuming with large scripts.

That said, the issue is fairly high on the wish list.

1 Like

As a user, personally, I would think the best approach would be for Script Debugger to detect that it is loading a debug script and pop up a warning that this is not supported.
An even better solution would be to save the debug information at the end of the file or in a separate file, so that when the file is loaded by a “load script” command, the AppleScript it can find the symbols it expects in the places it expects and debugging cannot ever break anything.
I think a debugger should not break functionality of code by enabling debugging no matter what the platform or language.
And finally, at least this should be clearly documented somewhere. Is it? I only found out by asking in this forum.
Just my 2 cents.

AppleScript is loading the script, not Script Debugger. Best you log a request with Apple.

From Help -> Script Debugger Help under Debug:

A script saved in debug mode is unusable except in Script Debugger. Therefore, when you’re finished debugging, you will probably want to save your script not in debug mode.

Perfect! Zing, I’m so glad it’s already documented and I just missed it. Thanks for taking the time to find this for me!