Debugging Hazel AppleScript

Thanks for joining us. I apologize for taking a while to reply, but I’ve been ill.

Rereading @mtennes’s responses to the OP, it appears that Hazel is not permitting users to select documents saved by Script Debugger when debugging is enabled.

As for OSAKit, it appears to be doing the right thing in terms of loading and executing scripts. Here is a sample Xcode project that loads and executes a simple script (Sample.scpt) with Script Debugger’s debugging enabled:

OSAKitTest.zip (276.8 KB)

And here’s a video showing the results I see here when I run this sample application:

https://s3.amazonaws.com/latenightsw.com/OSAKitExperiment.mp4

NOTE: In testing this, I did find a Script Debugger bug. If the Sample.scpt script is open in Script Debugger when the OSAKitTest app runs, then debugging proceeds as it is supposed to. However, if Script Debugger’s new document choose panel is the top-most window, then external debugging fails silently. I have a fix for this issue in hand which will become part of the next Script Debugger maintenance release.

I’ve downloaded the Sample Xcode project you provided, but I am not seeing the same behavior. Script Debugger NEVER comes to the front or has control at anytime. I have set breakpoints in Xcode at the script?.execute line. I have tried each of the files below, the first being the one in the Xcode project you provided (thank you) and the second being the scriptURL object (file) in the “ViewController.swift” file when it’s executed. Neither works. I obviously am missing something and if this simple example doesn’t work, it’s no wonder that the more complex Hazel case doesn’t.

~/Projects/OSAKitTest/OSAKitTest/Sample.scpt
~/Library/Developer/Xcode/DerivedData/OSAKitTest-gzzzuoonkuzqpxfeljritjibhgij/Build/Products/Debug/OSAKitTest.app/Contents/Resources/Sample.scpt

I should point out that I don’t think the AppleScript is running correctly wherever it is, because I don’t get the correct return result either. As shown below the returned value is always nil, not 600. Is there some Xcode property that I need to set?

       resuleDescriptor:  nil

I’m not really sure what to suggest. You can make a recording of your actions and the responses you are seeing and I’ll see if I notice something important.

Please ensure that Sample.scpt is open, and current, in Script Debugger before you run the OSAKitTest app from Xcode (this requirement will go away with the next Script Debugger 6 maintenance release).

Here’s what I see.

https://dl.dropboxusercontent.com/u/253031/OSAScriptFail.mp4

I do see that the script is failing to load with this error on my end:

OSAScriptErrorNumberKey = "-2147450879”

Doing a quick search doesn’t bring up anything. Does that error code ring any bells on your end?

In any case, I do have the sample script exhibiting the problem so I’ll look into that aspect of it here.

Thanks.

Doesn’t ring my bell which just goes ding dong, remember I’m a newbie to Script Debugger.

Looking at your recording, it appears that the script is failing to load. Because the script object is nil, nothing will happen when the OSAKitTest app goes to execute the script. Why this is happening is not clear. You can check your console log to see of anything useful was logged by the OSAKitTest application.

When Script Debugger launches, it installs a file called Script Debugger.component in the ~/Library/Components folder which facilitates external debugging. I can so no reason why this file would be missing since Script Debugger is running in your video, but it might be worth checking to make sure its there.

That is not an error number I recognize. Generally OSA error codes are small 16-bit values. The only 32-bit errors are these, but they don’t match:

/* ComponentError codes*/
enum {
  badComponentInstance          = (int)0x80008001, /* when cast to an OSErr this is -32767*/
  badComponentSelector          = (int)0x80008002 /* when cast to an OSErr this is -32766*/
};

Please check your console log and see if the OSAKitTest application logged anything. There may be a clue to the cause of the failure there.

Sorry, wasn’t clear before. It’s fine in the sample project but in Hazel, I get that error. Nothing logged so I’ll have to play with it more when I have some time.

Well, well, well… this might be a problem!```
Michael@Zadok:/Users/Michael>>ps -ax | grep cript
3310 ?? 0:31.56 /Applications/Script Debugger.app/Contents/MacOS/Script Debugger
3357 ttys000 0:00.00 grep cript
Michael@Zadok:/Users/Michael>>ls -la ~/Library/Comp*
total 0
drwx------+ 3 Michael staff 102 Mar 27 2012 .
drwx------@ 87 Michael staff 2958 Oct 28 09:08 …
-rw------- 1 Michael staff 0 Mar 27 2012 .localized
Michael@Zadok:/Users/Michael>>ls -la /Library/Components/
total 0
drwxr-xr-x 2 root wheel 68 Jul 30 17:59 .
drwxr-xr-x+ 67 root wheel 2278 Sep 8 18:14 …
Michael@Zadok:/Users/Michael>>

When I do as you have done I get these results:

mark-2:~ mall$ ls -la ~/Library/Comp*
/Users/mall/Library/Components:
total 16
drwx------   6 mall  staff   204 26 Oct 22:32 .
drwx------  92 mall  staff  3128 28 Oct 12:31 ..
-rw-r--r--@  1 mall  staff  6148 19 Jun 08:25 .DS_Store
drwxr-xr-x   3 mall  staff   102 26 Oct 22:24 Script Debugger.component

/Users/mall/Library/Compositions:
total 0
drwx------   3 mall  staff   102 16 Aug  2010 .
drwx------  92 mall  staff  3128 28 Oct 12:31 ..
-rw-------   1 mall  staff     0 16 Aug  2010 .localized
mark-2:~ mall$ 

If you lack a ~/Library/Components folder, then Script Debugger will be unable to install its Script Debugger.component file and external debugging will be inoperative.

Creating a Components directory where one was lacking solved all my problems. Including debugging scripts in Hazel. FEATURE REQUEST: Prompt users to create directory or do it automatically when required directory does not exist.

Fair enough, but this issue has never arisen before. The ~/Library/Components directory has, so far, always been there. I’m curious to know if you removed it at some point or if your system never had this directory.

FWIW, I just checked two test volumes. One I had started with a clean install of an early Sierra beta and updated from then on until 10.12 release, and it has a Components folder. The other was a clean install with either the Sierra GM or build before (I can’t remember exactly) and updated to 10.12 release, and it doesn’t have one.

That suggests a recent change…

I did not remove it. Looking back through my Time Machine backups, I don’t see it was there since Yosemite was the current OS.

Either way, to spare one user or potential buyer (that might not buy) the appearance that Script Debugger doesn’t work due to a simple problem that a directory might need to be created is worth the time needed to implement it. Look at all the time we’ve wasted resolving the issue.

BTW: This ~/Library/Components directory was not on ANY of my systems: MacPro, Mac Mini, MacBook Pro. (All running macOS Sierra)

I’m not arguing that Script Debugger should not do this. I’m just trying to understand if and when a change to the layout of the ~/Libraries directory happened. We’ll get this sorted out for the next Script Debugger maintenance release.

I hope I wasn’t perceived as being argumentative, my response was to satisfy your curiosity.:slight_smile:

No, not in the least. You found something totally unexpected and it took a while to sort out what was actually happening. The fix for the issue is in hand and will appear in Script Debugger 6.0.4.

Bit more info for you Mark, don’t know if this helps any.

No ~/Library/Components folder on my 10.7, 10.9 or 10.10 installs either. I don’t have SD on any of these.

On my 10.11.6 install, SD is installed and the Components folder is there. On one of my Sierra installs, the same. But on another, where I’ve only got a trial version of SD and which I don’t think I’ve even launched before just now the Components folder is missing.

That all suggests to me that the Components folder is created solely by SD. It seems that normally SD does create the needed folder, but for some reason that code is failing under certain circumstances.

Edit:

and which I don’t think I’ve even launched before just now the Components folder is missing.

I would have launched SD when I first downloaded it, but probably didn’t actually run any scripts (the Trial days remaining indicate that would have been about 11 days ago). Is it possible the code you call to install the Components is only in the first run, but also only called when a script is first compiled? If so, that might explain why its missing in some cases and not others.

So it looks like this was a regression introduced in 6.0.1 (#641). Before that SD was indeed creating the folder if it didn’t already exist.