Anyway to know that a JXA/AS script was called by Hazel?

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

I am wondering if there is a reliable way in a JavaScript called by Hazel, to know that it was called by Hazel and not Script Editor or CodeRunner.

When developing JavaScript for a smart rule in DEVONthink, I am able to get the current app and switch accordingly in my script, but that doesn't seem to work for Hazel.

I can get the front most app but that doesn't seem robust.

The reason for the request is so that I can fill `theFile` when in dev mode, and skip that code when Hazel is the parent.
farf
 
Posts: 4
Joined: Wed Mar 02, 2016 4:10 pm

Is this an external script being shared by all programs? Hazel does require a specific handler so it would seem to me that you can do whatever Hazel-specific logic in that handler.
Mr_Noodle
Site Admin
 
Posts: 12170
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Thanks for the reply.

Unfortunately I didn't make myself clear.

What I am trying to do is have one piece of code that I can develop outside of Hazel, but then also call from Hazel once debugged.

My testing shows that in the case of JavaScript, the script is loaded and run before then calling the hazelProcessFile() entry point.

I have a self-executing function that is run each time that Hazel runs the script and I would like to place some logic in the "iife" that switches based on whether Hazel is running. This happens before entering hazelProcessFile().

Here is an outline of the code:

Code: Select all
/* anonymous self-executing function permits to run this in script editor etc     */
/* We need to determine if we are running in Hazel, so that `theFile` can be set  */
(() => {

   const thisApp = "Script Editor" // I want to dynamically detect Hazel or not Hazel here

   if (thisApp !== 'Hazel') { // don't run in Hazel to prevent hazelProcessFile() running twice
// logic goesj here to set `theFile` and any `inputAttributes`

  hazelProcessFile(fullPath, inputAttributes));
   } else { //Hazel
      // do nothing here
   }
})();
farf
 
Posts: 4
Joined: Wed Mar 02, 2016 4:10 pm


Return to Support