Are there any guides to start slow with scripting? Thanks
I found the W3Schools JavaScript tutorial very useful.
Regards, AB
Thanks, as I look at it more it is making sense. I think I was not starting in the correct place in the documentation. I have worked with JavaScript for years (web dev) but it was not all making sense. I see now that anything in the command reference can be accessed via scripting. I am going to read a lot. Thanks again.
Also consider doing a search on the forum for jscript or scripting tutorials, we had several threads listing some good resources.
Maybe post your findings, so they can be made sticky or something as this topic comes up regularly.
This stuff is addictive! I began looking a the example scripts. I figured I could look at the examples there and get them to fit things that I wanted to do. I understand a little VB, but decided to try to convert some of the Example scripts that were in VB to JScript. I was successful with the ones that display dialogues. I have a script here I would like some help with. I can not seem to understand the way you work with a script running the Opus commands. Here I want the script to create a new file with the extension I choose. Also do I have to make that specific to a window or tab or will the displaying directory get this file created?
@script jscript
var dlg = DOpus.Dlg
var cmm = DOpusFactory.Command
dlg.message = "Create a file of type"
dlg.title = "New File"
dlg.buttons = "OK"
dlg.icon = "warn" // can change later to better
dlg.max = 128
dlg.options(0).label = ".php"
dlg.options(1).label = ".html"
dlg.options(2).label = ".c"
dlg.options(3).label = ".js"
dlg.options(4).label = ".xml"
dlg.Show
DOpus.Output (dlg.input)
if(dlg.options(0).state) {
cmm.RunCommand ("FileType NEW .txt")//DOpus.Output (".php")
} else if (dlg.options(1).state) {
DOpus.Output (".html")
} else if (dlg.options(2).state) {
DOpus.Output (".c")
} else if (dlg.options(3).state) {
DOpus.Output (".js")
} else if (dlg.options(4).state) {
DOpus.Output (".xml")
} else {
DOpus.Output ("you forgot something!")
}
I figured I could write a function to do the choice much nicer but wanted to full understand somethings first. Thanks
If you're running the script from a button, your OnClick function is passed a command object that is already set up to use the active folder tab (clickData.func.command).
If you create a command object from scratch, you need to tell it which folder tab is the source (or you can give it a folder path to work on, but it usually needs one or the other). If you don't do that then it might pick the active window's active tab, but you don't want to leave that to chance; it's best to be explicit or random things may start happening when you least expect it.
DOpusFactory is the type of the factory object, but not its name. That DOpusFactory.Command line is presumably resulting in an error message in the log (and a flashing icon in the status bar if the log isn't open) when you run the script. DOpus.Create.Command is the proper way.
I also had no luck with the line that seems to be selecting a window in the the VBScript (that I tried to convert to Jscript). If in JScript what is wrong here? Thanks
dlg.window = DOpus.Lister(0)
Taking a step back, why are you trying to get the first lister? What's the aim?
The first lister may not be the one you want, and you'll usually be given the correct window to use, often with command and dialog objects that have that window (and other details) already set up correctly.
Thank you so much for all the prompt responses as usual. Actually I thought from the VB I was reading (before) conversion to JScript, that it would be necessary. I had no aim. When you said that it might be left to chance which windows active tab it chooses, I thought it better not be left out. I am still brushing up on what particular Opus objects do and how they work. Could not imagine things being this clever and useful. This is super! You guys man.....! Thanks
I am so pleased with this simple script that makes my life easier. I hope that some one can benefit from what I picked up and the corrections more experienced users can suggest. Also could a script like this be ran from a right click context menu? Thanks
@script jscript
var dlg = DOpus.Dlg
var cmm = DOpus.Create.Command
dlg.message = "Create a file of type"
dlg.title = "New File"
dlg.buttons = "OK"
dlg.icon = "warn" // will change to better fit later
dlg.max = 128
var typs = [".php", ".html", ".c", ".js", ".xml"]
var i
for (i = 0; i < typs.length; i++) {
dlg.options(i).label = typs[i];
}
dlg.Show
for (i = 0; i < typs.length; i++) {
if(dlg.options(i).state) {
cmm.RunCommand ("FileType NEW .txt NEWNAME norename:" + dlg.input + typs[i])
}
}
I wanted a way to make my localhost document path files able to be launched directly. The Opus command
Clipboard COPYNAMES=url REGEXP "file:///C:/Apache24/htdocs/(.*)" "http://localhost/\1"
"C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" {clip}
was great and getting the job done. For me I use a clipboard manager to review and used pasted clips. It seemed like it could be better if I could come up with a way to launch these files with out an entry in the clipboard. There were many duplicates with the way I was doing it. This scrip is what I came up with.
@script jscript
function OnClick(clickData) {
cmm = DOpus.Create.Command
enumFiles = new Enumerator(clickData.func.sourcetab.selected) // Creates an object good to move and manipulate files
enumFiles.moveFirst()
count1 = 0
checkPath = "C:\\Apache24\\htdocs" // Sets the saftey so has no effect in wrong directory
pathMain = !enumFiles.item() ? 0 : enumFiles.item().path
if (String(pathMain).indexOf(checkPath) >= 0) {
while (enumFiles.atEnd() == false) { // while is great to move through Enumerator,shown by Opus staff
count1++ // I felt could be useful later but not needed
//DOpus.Output(enumFiles.item())
str = String(enumFiles.item())
//DOpus.Output(str)
res = str.replace(/\\/g, "/")
//DOpus.Output(res)
res2 = res.replace("C:/Apache24/htdocs", "http://localhost");
DOpus.Output(res2)
cmm.RunCommand ("C:\\Program Files (x86)\\Mozilla Firefox\\firefox.exe" + " " + '"' + res2 + '"') // run firefox or any browser with command
enumFiles.moveNext()
}
}
}
Now I have a way to do it and not take up space in my clipboard. I can find important stuff that was pasted and not have many duplicate entries. I welcome some advice and constructive ideas. I don't know what I am doing.. yet but Opus scripting is starting to make sense and is pretty fun. Thanks
I have noticed when the COPYNAMES command is used, Opus does not make a button it is assigned to clickable until there is a selected file or folder. This makes total sense. I am wondering how to make use of something like this in a script. Which area of Scripting deals with these options? Thanks
You can add @disablenosel to the top of any button function definition to get the same effect.
Thanks!
I see that in VB scripts you can create a multi-line message withdlg.message = "More complex dialog message." & vbCrLf & "Enter
is there an equivalent for vbCrLf in jScript? I have tried with "\n" and even "\r" with no luck. Thanks
I mean \n \r sorry
Try \r\n
That did the trick. Thanks
I am creating a script that uses a command that will create an archive something likecmm.RunCommand ("Copy HERE ARCHIVE=.zip CREATEFOLDER=" + zipName(subject))
When an archive exists already with same name it gives the options in the picture. I have created a script that uses the option for a dialog (one I created) with the results property being a way to use its returned value e.g.if (savePath.result) {
...
}
How do you use a default Opus generated messages' “results” property or returned value in your own script?
I'm not sure what the question is asking. There are lots of ways to use the results property. What is it that you want to do with it?
Please also start a new thread for separate questions (see the one question per thread link at the bottom of the FAQs for reasons).