Starting Scripting

For Toolbar Commands and Shortcut Keys, DOpus allows:

  • Standard Function (Opus or external)
  • MS-DOS Batch Function
  • In addition to Script Function

How can we do basic debugging of Standard Functions (Opus or external) and MS-DOS Batch Functions.

Ie, for Standard Functions and MS-Dos Batch functions how do we do the equivalent of:

  • DOpus.Output()
  • DOpus.Dlg.Show()

In MS-DOS, the echo command lets you write text to the command prompt. (You might want to add the pause command at the end, so the prompt remains open.)

In Standard and MS-DOS, you can use dopusrt /argsmsgbox Hello World to display text in a message box, or Tbone's "say" script add-in to put text into the script output log.

Can anyone help with this script please? The idea is so I can select create a file with dropdown list?

// @language=JScript

function OnInit(initData) {
    initData.name = "NewFileDialog";
    initData.version = "1.0";
    initData.default_enable = true;

    var cmd = initData.AddCommand();
    cmd.name = "NewFileDialog";
    cmd.method = "OnNewFileDialog";
    cmd.desc = "Create a new file via dialog";
}

function OnNewFileDialog(scriptCmdData) {

    var tab = scriptCmdData.func.sourcetab;
    var path = String(tab.path);

    var dlg = scriptCmdData.func.Dlg;
    dlg.resource = "UI";
    dlg.title = "Create New File";

    dlg.Create();

    var ctlName = dlg.Control("filename");
    var ctlExt  = dlg.Control("extlist");

    ctlExt.AddItem(".ahk");
    ctlExt.AddItem(".ini");
    ctlExt.AddItem(".md");
    ctlExt.AddItem(".txt");
    ctlExt.value = ".ahk";

    if (dlg.Show() != 1) return;

    var filename = ctlName.text;
    var ext      = ctlExt.value;

    if (!filename || filename.trim() == "") return;

    var fullpath = path + "\\" + filename + ext;

    var cmd = scriptCmdData.func.command;
    cmd.ClearFiles();
    cmd.AddLine('FileType NEW="' + fullpath + '"');
    cmd.Run();

    cmd.ClearFiles();
    cmd.AddLine('FileType OPEN="' + fullpath + '"');
    cmd.Run();
}

It probably would have been a better idea to start a new thread regarding your specific expectations, rather than necroing a 10 yo thread about scripting in general.
Then, describing what's not working with your script would also help.
So i'm gonna guess that the file gets created but you can't open it. If so, that would be related to the fact that the FileType command has no OPEN= option (see FileType [Directory Opus Manual]).

I had few occasions where I needed to open files, I did so either by specifying the path to the program to open followed by the filepath (that requires the program to accept such syntax).
Just trying to "execute" the file might also work (try cmd.RunCommand('"' + fullpath + '"');.
But looking at the FileType manual, maybe cmd.AddLine('FileType open "' + fullpath + '"'); could work.

EDIT: After a quick direct test of FileType, I think what you need to do is to replace:

    cmd.ClearFiles();
    cmd.AddLine('FileType OPEN="' + fullpath + '"');
    cmd.Run();

by

    cmd.ClearFiles();
    cmd.AddFile(fullpath);
    cmd.RunCommand('FileType open');

EDIT2: On second thought, the cmd.ClearFiles() should even not be necessary, since you already cleared it, and did not add any file. And the first two calls on cmd: AddLine and Run can also be replaced by a single call cmd.RunCommand('FileType NEW="' + fullpath + '"');.

I do apologize, I should of started a new thread.

The script runs but no dialog opens, therefore no file created.

Because there is no easy way in DOpus to create a file with a dropdown to select or add for next time, I found it earlier to compile a small exe to run in a button and Dopus sends the source folder to my exe where I type in the FileName and in the dropdown I can select or add a file type, then click ok. I will now just add new modules to my exe if neeed..

Again, I do apologize for not starting a new thread, I'll remember if there is a next time.

I thought you stripped the dialog definition, but it might just be the problem here.
You need to design the dialog (in the script editor, resources). It will have a name you can change, and then in the command code, before calling Create, you need to specify the template property of the dlg object with the name of your dialog.

See here:

And here:

Thx, for your help, but to do a simple thing as create new file and choose a file type, I find it much easier to compile own exe.

OK, no pb.
It looks like you're actually only creating text files.
If so, you could make a button for each type with the following command (no need for a script):

FileType NEW .txt NEWNAME "iniFile.ini"

This is an example for an ".ini" file. Just make one for each type and put them in a menu.
Note that, by default, FileType NEW enters inline rename after creating the file, meaning you just can edit the filename ight after clicking the button without having to do anything else but typing the name.

And to edit it ... press enter twice (first to validate & exit the rename, second to execute the open action) ...

Sounds easier to me than compiling an exe and stays fullly inside opus, which means better performance. But it's entirely up to you.

1 Like

Hi, Yes did did use Dopus FileType NEW to popup a edit dialog to type in name with filetype I wanted, I use for few yrs, however thought if I did java script so can do a dropdown list (.ini, .txt, .js, .doc, etc. add to the list if not there & auto save) but never got it to work, would of been cool all inside DOpus.

As for my module, you see I have a small app.exe always running in the background of my PC only using 2-4mb memory as a command center, everything on my PC is one hotkey away, so I just thought I would add a module to do it, it's only few few lines of code (far less than the java script), now I can call it from anywhere, not just DOpus.

Again, would of been cool all inside DOpus.

Thx for your help.

This script might help:

How to Create New/Empty Files

Just wanted to say thank you guilotane, just what I was looking for.