RTTSoftware Support Forum
PDF-ShellTools => General => Topic started by: Nick Riviera on January 26, 2024, 09:55:43 AM
-
Hello!
With the rename tool , can I use parameters in a javascript function?
function test(x) {
var dt = new Date();
var dx = dt.getDate() + x;
return dx
}
-
You can pass one parameter to the script using this notation:
[ScriptName](parameter)
and access it from the script, as a string type, with CurrentField.value
Using your example, the expression needs to be:
[f]_[test](value)
And the script:
function test() {
var dt = new Date();
var dx = dt.getDate() + CurrentField.value;
return dx
}
The parameter can be the result of another expression:
[ScriptName](1,5,3,[script2])
Because in this case it contains a separator, you can emulate passing multiple parameters:
var parameters=CurrentField.value.split(',');
-
Thanks. cool. parameters works...
I would ask, how I can run a custom script rename files with a shortcut
I tried with this script but it doesn't work for me
CallShellTools.js shortcut: C:\ProgramData\Microsoft\Windows\Start Menu\Programs\PDF-ShellTools
Target: C:\Temp\CallShellTools.js Script RunScript "ScriptName=test"
var PDFShellToolsExePath = "C:\Program Files (x86)\PDF-ShellTools\PDFShellTools.exe";
var ShellApp = new ActiveXObject("Shell.Application");
var SelectedFiles = [];
var Windows = ShellApp.Windows();
for (var i = 0; i < Windows.count; i++) {
var Window = Windows(i);
if (Window.FullName.toLowerCase().indexOf("iexplore.exe") == -1) {
var SelectedItems = Window.Document.SelectedItems();
for (var n = 0; n < SelectedItems.count; n++) {
var SelectedItem = SelectedItems.Item(n);
SelectedFiles.push(SelectedItem.Path);
}
}
}
if (SelectedFiles.length > 0) {
var SelectedFilesList = SelectedFiles.join(';')
var ArgumentsList = '';
for (i = 1; i < WScript.Arguments.length; i++) {
ArgumentsList += '"' + WScript.Arguments(i) + '" ';
}
ShellApp.ShellExecute(PDFShellToolsExePath, WScript.Arguments(0) + ' ' + ArgumentsList + ' "' + SelectedFilesList + '"', '', '', 0);
} else {
var sapi = new ActiveXObject("sapi.spvoice");
sapi.Speak("No files selected");
}
-
You have to escape (https://codedamn.com/news/javascript/how-to-escape-a-string-in-javascript) the backslash characters in a JavaScript string.
var PDFShellToolsExePath = "C:\\Program Files (x86)\\PDF-ShellTools\\PDFShellTools.exe";
Take note that you can use the scripts API from an external script directly. No need to call an internal script from an external one. You just need to register the pdfe root object (check the attached screenshot), and then initiate it as usually with any other ActiveX object.
var pdfe = new ActiveXObject("MyScripts.PDFEObject");