How to learn scripting?

This is totally irrelevant to your question but may I ask you how did you learn all the scripts in Directory Opus? I would love to try to get a program to work with Directory Opus but I have no idea how to do so. It would be a complicated project, I know.

Just wondering how does one becomes an expert at Directory Opus? The manuals doesn't seem to go into that much depth about the coding and programming. How do you some of you guys figure it out?

@SoBreezyInChile You may be faced with an age-old problem when it comes to a new "system." If you don't have a question that needs an answer, it's hard to know how to build an answer.

Just like in mathematics, if you don't have a need for a mathematical solution, it's hard to come up with the mathematical formula.

The same goes for programming, including scripting. Find a question or need that needs to be answered or fulfilled. Then, use the references in the manual (which truly is complete) or search here on the forums to try to find out how to build your answer.

It might help if, in the beginning, you stick with one "extra" language. DOpus can have scripts in Visual Basic Script (aka, vbscript and vbs) or Javascript (aka js). If you don't know either, pick one and stay with it for now until you feel comfortable switching to the other.

image

There is a multitude of ways you can create your vbs scripts. I recommend Visual Studio Code. It's a free code editor (aka text editor for programming) that has lots of nice features like syntax highlighting and auto-completion.

If I were to dip my toes into js, I'd probably go with something like atom (https://atom.io/). Just like Visual Studio Code, it's a beefed-up text editor with lots of cool features to help programmers write their code.

As for how to learn those two scripting languages, that goes way beyond the scope of Directory Opus' manuals, these forums, or even this reply.

There should be tons of material for "getting started with" and/or "beginner's" guides on both VBScript and Javascript. [Note: In both cases, I just picked the first reasonable result from a search on YouTube and used them as links.]

3 Likes

I had experience in Javascript from web and API server development. So I started there.

I just switched to VS Code. TBH it can be painful to get started in a new editor while learning a new language. Just a warning, the Javascript support in VS Code includes a tool called Prettier which reformats your code when you save it to keep it neat and compliant (fixes semicolon usage, comma's etc). By default Prettier will format your code using features which are beyond the level of Javascript which Directory Opus support.

The supported Javascript standard is quite old. Javascript is rapidly evolving, and any script you write in DO will require you to avoid any Javascript features less than 10 years old.

There are a surprisingly large range of script types. Its entirely up to you which you use. I find I need to use them all in different contexts.

  1. Script Addins which may include source files and dialog metadata, all zipped into a single file with the extension changed to .osp (All saved in /dopusdata/Script Addins). These can be enabled/disabled via Preferences and can have configuration dialogs. I'm fairly sure this is the only place you can add global triggers (eg, OnBeforeFolderChange()), custom columns.

  2. Rename Scripts which are built into the Rename dialog (I write them in VS Code and paste then into the rename dialog for testing. Not ideal but certainly quicker due to the limitations of the built in editor.). These are saved as Presets directly in the rename dialog.

  3. Every button can include a script. You would usually switch the button editor from Standard Function to Script Function (You may need to hit the Advanced... button to even see it). You could then write a function called OnClick() which gets launched whenever the button is clicked on. This is saved in the button metadata.

  4. In the Customize... dialog the Commands tab has a section called User-defined Commands. You can create a function, again called OnClick() and assign a command name to it. You can then use the Command name anywhere you would use a DO command, including from dopusrt /cmd <commandname> which allows you to remotely trigger scripts.

  5. The Ad-Hoc Script Editor in the Tools menu. The script editor lets you write and test scripts with full access to the DOpus object. You can access the currently active lister, test regular expressions and generally try out new things. Its an easy way to run code to make sure it does what you want before pasting it into a script elsewhere.

There are most likely more... including a /dopusdata/Scripts directory which I've never figured out the use for...

I started by tweaking existing scripts from the Scripts forum. The manual is your friend. Hit F1 and search for Script in the index. Everything you need is there, but it has almost no examples or templates. Use other peoples scripts as templates and read the manual to understand what they are doing.

Just remember the scripts which end in .osp can be extracted to show you the javascript source. (You may need to rename them to .zip if you are relying on Windows to extract the files).

2 Likes

Thanks for your thoughtful answer. You remarked that it was unfortunate I didn't have a problem to go along with the learning the language. I actually have a question/problem I want to resolve! If you could tell me if it's too big of an undertaking, please let me know. If it's going to take me weeks of intense hours, forget it. But, if it's doable for a weekend, I'll definitely be up for it.

There is a program called FileMeta which is a property handler that stores metadata for almost every type of extension. You can customize the metadata fields that's on the Details page of the file's Properties page, InfoTips, and the Metadata panel.

Directory Opus doesn't recognize these files and I was hoping that I could create something that could allow Directory Opus to read the metadata fields. The metadata files that are created by this program called FileMeta are XML files. I just want Directory Opus to read these XML files and then add the metadata fields to Directory Opus's Metadata Panel, InfoTips, and a file's Details Page within Properties.

Do you think that it's something that I could do in a short time?

Not sure about a "short time" - that depends how quick you pick it up.

From an Opus script you could show this info in Columns, a custom dialog, InfoTips and as rename codes but not directly in the Metadata panel, or the Properties page afaik.

1 Like

I've split this into a new topic.

If your post begins with "this is totally irrelevant" then you should already know it should be in a separate topic.

The manual goes into depth about everything that is specific to Opus. But the manual is not aiming to teach you how to program in general. There are hundreds of guides to that already on the web.

There's also some earlier discussion here:

(There maybe some other forum threads with links as well but I am not sure. Found that one from a quick search.)

1 Like