Can any of our holidaying coding gurus point out why this simple script segment is failing? Please note that I am using the latest Directory Opus version 13.12. When I save this section of the main code in the DO Script Editor, the parser returns the following error:
'Test.js: SimplisticTest OnInit Error: Object doesn't support this property or method.'
The code segment error is a puzzle I need to solve to complete the main code. Once I resolve the issue, I will share the functional script for others to use. I believe it will serve as a helpful directory cleanup tool, provided I can get it to work as intended.
Not sure about the initData.resources too : not documented and I've never seen this before.
Usually, resources are at the bottom of the script like this :
And you should also avoid using try/catch when there's no real reason for it : it makes the script harder to read, introduces one more level of indentation, can mask errors, ...
Is this AI generated ?
EDIT : One more, unless you specifically extended the DOpus object, there's no Message method for this object (DOpus.Message("SimplisticTest Error: " + ex.message);), so same type of error you already get will keep coming.
EDIT2 : since the error you get is from the OnInit method, it most probably comes from the initData.resources call.
I am currently trying to learn Python just as a hobby. So I am using AI as a learning platform. Surprisingly, I have had good results using Python and AI. Together, we designed a reasonably sophisticated engineering application using Anaconda and AI. Anaconda is a web-based platform, as you are probably aware. In my view, it is a brilliant way to learn Python scripting because you can break the code into small chunks and test each section of the code before proceeding. I am not a programmer and don't intend to be, but naively, I thought the same approach might work for JScript. I quickly learned that Directory Opus JScript implementation is minimal implementation. I don't know JScript, but it looks like a very unstructured language, unlike Pascal, which I learned at Uni many years ago on a PDP-11. It, therefore, does not appeal to my sensibilities. After doing this simple test script, I found out that the AI was trying to write the JScript as a Command-Based Script when an Event-Based code was more useful for what I intended to do. I will persist, but ultimately, I think it will be too hard as I will have to read and understand how DO structures its JScript, which AI cannot understand, at least at this point. Here is the output from the AI that was used to analyse this code.
Your SimplisticTest.js script attempts to define a command using initData.AddCommand(), which is suitable for command-based scripts. However, the provided sample script uses an event-based approach with an OnClick function. Here's a brief overview of both:
Command-Based Scripts:
Definition: Define commands that can be bound to buttons, menu items, or keyboard shortcuts.
Structure:
Use initData.AddCommand() in the OnInit function to register the command.
Define methods that execute when the command is invoked.
Use Case: When you want to create reusable commands that can be invoked from various parts of the interface.
Event-Based Scripts:
Definition: Respond to specific events, such as button clicks.
Structure:
Define event handler functions like OnClick.
Access event data via parameters like clickData.
Use Case: When you want to handle specific UI interactions directly.
Recommendation:
Given that the MinimalInit.js works and your sample script successfully uses an event-based approach, adopting an event-based script might be more straightforward for your needs. This approach avoids potential complexities and compatibility issues associated with command-based scripts.
It's great you're trying to learn a programming language !
A few remarks :
There's no real Opus JScript implementation : Opus is using the JScript engine provided by Microsoft, which is an old attempt to implementing Javascript (for old versions of IE). They just managed to inject the Directory Opus object model so you can interact with Opus (all the objects you can find in the Reference/Scripting section of the manual).
Beware of AI when you're trying to use it for something that doesn't have a large codebase to rely upon (such as Opus scripting ) : AI will tend to improvise and invent objects or properties or methods that do not exist.
I've never used AI as a learning platform, but from what I could test, it's more usefull when you want a quick skeleton of what you're trying to achieve, then refine it using your knowledge of the language/platform and what AI told you to refine it or just finish the job by yourself. This also has to take into consideration the previous point, meaning trying to do that for Opus script will definitely lead you on the path you've taken (non existing objects, properties, methods). And if you don't really know what you're doing, you'll get stuck (and probably frustrated).
AI explanations are sometimes a bit weird : looking at the two definitions for command-based and event-based is a great example : one is to define commands to be bound to buttons and the other one respond to button clicks !!!
In Opus, most of the scripting if event based since it will be triggered either by button clicks/keyboard shortcuts or directly by some event (clipboard change, folder content change, ... : see Reference/Scripting reference/Scripting events).
Yet, if your script is building a command with no UI, most of it will look like command-based except for the entry point giving you the context. You'll define functions that do stuff and your main entry point function will just call sequentially these different functions.
If you add an UI, you'll have two possible paths (as described in the manual section Scripting/Script dialogs and the sub-sections) : simple dialogs and detached dialogs.
FWIW : Pascal, JScript, Python are all structured programming languages.
My advice if you want to move forward with JScript and Opus : take it slow and step by step.
Try to find small use cases where scripting would be interesting, and try to get your hands on the javascript syntax and objects, or find small interesting scripts on this forum and try to understand how they work.
I gave up after playing around with AI to generate JScript for DO. However, I have found why AI may have difficulty with DO JScript, whereas it seems to succeed with Python. My hunch is that it cannot understand the correct functions and methods to use for the DO API calls to ECMAScript 5 (ES5), which I think is the version of the API that DO may be using. I asked AI a question about DO JScript API implementation, and it gave me the following information:
Does the ECMAScript 2024 (15th edition) version run legacy code? If not, may I suggest that Python be implemented for future versions of the scripting language? It will not worry me because, according to the NSW Government, it doesn't concern me too much as I am a senior citizen. Still, for the younger adopters of Directory Opus, since Python is now ubiquitously taught at most Universities, I think it would be wise to allow Python scripting for the next version of DO, in my humble opinion.
ECMAScript 5 (ES5) was published in December 2009, making it over 15 years old as of January 2025.
There are some examples in the manual for dialogs including drop down controls. Unfortunately they are in vbscript. But I'm guessing you can easily convert them to jscript using AI.
Thank you, but I am a novice at best when it comes to Java Script. Unfortunately, I know nothing at all about VB Script. I last used basic on an Apple II in circa 1979. Object-orientated coding had not even been invented then. Well, maybe there were earlier research versions in Xerox Palo Alto Research Center; who knows, I wasn't there. Maybe when Joanthon returns from annual holidays, he could include some in the DO documentation because neither ChatGPT nor Claude 3.5 Sonnet.
If your dropdown list is static, I'd go with a simple dialog (not detached) : it will prevent you from the hassle of managing the message loop and designing controls.
Look at the scripting dialogs section of the manual :