Morbid
January 21, 2025, 6:41pm
1
Forgive me as i am barely know how to make a simple script for a button... But maybe someone can help?
I need a script to delete file 1 and 3 and rename file 2 (with an exported rename function, it looks like like Rename PRESET="preset name here" ) if all 3 files are selected. The order in which the operations are performed is not important.
Can someone help, please?
lxp
January 21, 2025, 7:17pm
2
Try this.
// https://resource.dopus.com/t/script-to-delete-file-1-and-3-and-rename-file-2-if-all-3-files-are-selected/54245
// 2025-01-21
function OnClick(clickData) {
var cmd = clickData.func.command;
var tab = clickData.func.sourcetab;
if (tab.selected_files.count != 3) return;
cmd.RemoveFile(tab.selected_files(1));
cmd.RunCommand('Delete QUIET');
cmd.ClearFiles();
cmd.AddFile(tab.selected_files(1));
cmd.RunCommand('Rename PRESET="preset name here"');
}
XML
<?xml version="1.0"?>
<button backcol="none" display="label" hotkey_label="yes" label_pos="right" textcol="none">
<label>54245</label>
<tip>script-to-delete-file-1-and-3-and-rename-file-2-if-all-3-files-are-selected</tip>
<icon1>#script</icon1>
<function type="script">
<instruction>@script JScript</instruction>
<instruction>// https://resource.dopus.com/t/script-to-delete-file-1-and-3-and-rename-file-2-if-all-3-files-are-selected/54245</instruction>
<instruction />
<instruction>// 2025-01-21</instruction>
<instruction />
<instruction>function OnClick(clickData) {</instruction>
<instruction> var cmd = clickData.func.command;</instruction>
<instruction> var tab = clickData.func.sourcetab;</instruction>
<instruction />
<instruction> if (tab.selected_files.count != 3) return;</instruction>
<instruction />
<instruction> cmd.RemoveFile(tab.selected_files(1));</instruction>
<instruction> cmd.RunCommand('Delete QUIET');</instruction>
<instruction />
<instruction> cmd.ClearFiles();</instruction>
<instruction> cmd.AddFile(tab.selected_files(1));</instruction>
<instruction> cmd.RunCommand('Rename PRESET="preset name here"');</instruction>
<instruction>}</instruction>
</function>
</button>
How to use buttons and scripts from this forum
2 Likes
Morbid
January 21, 2025, 8:52pm
3
Thank you very much! It worked like a charm!