ped
May 6, 2024, 2:56pm
1
In my toolbar I have a button for Notepad:
Now, i would like to distinguish between the following scenarios:
If I click on the Notepad-Button, then open the Notepad with the selected file. This I achieve as follows:
cd %USERPROFILE%
@async:"C:\PortableApps\Notepad++\notepad++.exe" "{filepath}"
Now, i would expand the script to do this:
If the CTRL-key is pressed during clicking the button, then just open Notepad (without the selected file)
This was my first approach using JScript:
function OnClick(clickData)
{
var exeNotepad = "C:\\PortableApps\\Notepad++\\notepad++.exe";
if (clickData.func.qualifiers == "ctrl") {
var strCmd = '"' + exeNotepad + '" "' + filepath + '"';
DOpus.Output(strCmd);
clickData.func.command.RunCommand(strCmd);
} else {
var strCmd = '"' + exeNotepad + '"';
DOpus.Output(strCmd);
clickData.func.command.RunCommand(strCmd);
}
}
No, I got the error, that "filepath" is unknown. So, how can i use {filepath} in JavaScript?
Please bear with me, these are really my first attempts at script programming with DOPUS.
Leo
May 6, 2024, 3:34pm
2
No need for scripting in this case. You can use @keydown in a non-script command:
cd %USERPROFILE%
@keydown:!ctrl
@async:"C:\PortableApps\Notepad++\notepad++.exe" "{filepath}"
@keydown:ctrl
@async:"C:\PortableApps\Notepad++\notepad++.exe"
ped
May 6, 2024, 3:38pm
3
Thank you, Leo. It works like a charm.
Only for learning purpose and if it does not take too much of your time: How would I concatenate the string in JavaScript:
var strCmd = 'Notepad.exe' + {filepath};
How can I access the value of {filepath}?
Leo
May 6, 2024, 3:44pm
4
Have a look at the example/default script that you get when creating a new button and switching it to script mode. It shows how to use Opus's scripting objects to get filepaths etc.
Things like {filepath}
only work in commands, not the script code itself. You can use it as part of a command line, but you'd just literally include it in the string, not convert it to an actual filepath. To get the filepath as a scripting variable, you'd use the scripting objects instead.
ped
May 7, 2024, 1:25pm
5
Thank you very much, Leo. I see this for the first time. Shame on me.